"Bash 실행결과를 변수에 담기"의 두 판 사이의 차이

잔글 (Jmnote 사용자가 Bash 실행결과 변수에 담기 문서를 Bash 실행결과를 변수에 담기 문서로 옮겼습니다)
10번째 줄: 10번째 줄:
</source>
</source>


==실습==
==실습 1==
<source lang='dos'>
<source lang='dos'>
[root@jmnote ~]# whoami
[root@jmnote ~]# whoami
24번째 줄: 24번째 줄:
[root@jmnote ~]# echo $STR2
[root@jmnote ~]# echo $STR2
root
root
</source>
==실습 2 (여러 줄)==
<source lang='dos'>
[root@jmnote ~]# df -Pk
Filesystem        1024-blocks      Used Available Capacity Mounted on
/dev/mapper/VolGroup00-LogVol00  27678892  18857380  7392828      72% /
/dev/xvda1              101086    36768    59099      39% /boot
tmpfs                  524288        0    524288      0% /dev/shm
</source>
<source lang='dos'>
[root@jmnote ~]# STR3=`df`
[root@jmnote ~]# echo $STR3
Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/VolGroup00-LogVol00 27678892 18857392 7392816 72% / /dev/xvda1 101086 36768 59099 39% /boot tmpfs 524288 0 524288 0% /dev/shm
</source>
<source lang='dos'>
[root@jmnote ~]# echo "$STR3"
Filesystem          1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      27678892  18857392  7392816  72% /
/dev/xvda1              101086    36768    59099  39% /boot
tmpfs                  524288        0    524288  0% /dev/shm
</source>
</source>



2014년 7월 5일 (토) 01:08 판

1 개요

Bash 실행결과 변수에 담기
리눅스 쉘 표준출력 변수에 담기
변수명=`명령어`
변수명=$(명령어)

2 실습 1

[root@jmnote ~]# whoami
root
[root@jmnote ~]# STR1=`whoami`
[root@jmnote ~]# echo $STR1
root
[root@jmnote ~]# STR2=$(whoami)
[root@jmnote ~]# echo $STR2
root

3 실습 2 (여러 줄)

[root@jmnote ~]# df -Pk
Filesystem         1024-blocks      Used Available Capacity Mounted on
/dev/mapper/VolGroup00-LogVol00  27678892  18857380   7392828      72% /
/dev/xvda1              101086     36768     59099      39% /boot
tmpfs                   524288         0    524288       0% /dev/shm
[root@jmnote ~]# STR3=`df`
[root@jmnote ~]# echo $STR3
Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/VolGroup00-LogVol00 27678892 18857392 7392816 72% / /dev/xvda1 101086 36768 59099 39% /boot tmpfs 524288 0 524288 0% /dev/shm
[root@jmnote ~]# echo "$STR3"
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      27678892  18857392   7392816  72% /
/dev/xvda1              101086     36768     59099  39% /boot
tmpfs                   524288         0    524288   0% /dev/shm

4 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}