"리눅스 여러 줄 출력을 배열에 담기"의 두 판 사이의 차이

39번째 줄: 39번째 줄:
*http://ubuntuforums.org/showthread.php?t=1555275
*http://ubuntuforums.org/showthread.php?t=1555275
*http://www.linuxquestions.org/questions/linux-general-1/store-multi-line-output-into-an-array-in-a-linux-bash-script-706878/
*http://www.linuxquestions.org/questions/linux-general-1/store-multi-line-output-into-an-array-in-a-linux-bash-script-706878/
*http://stackoverflow.com/questions/16831429/when-setting-ifs-to-split-on-newlines-why-is-it-necessary-to-include-a-backspac


[[분류: bash]]
[[분류: bash]]

2014년 7월 5일 (토) 02:07 판

1 개요

Store multi-line output into an array in a Linux bash script
Bash 여러 줄 출력을 배열에 담기
리눅스 여러 줄 출력을 배열에 담기
IFS=$'\n' 배열변수명=(`명령어`)

2 실습

[root@jmnote ~]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      27678892  18857720   7392488  72% /
/dev/xvda1              101086     36768     59099  39% /boot
tmpfs                   524288         0    524288   0% /dev/shm
[root@jmnote ~]# IFS=$'\n' ARR=(`df`)
[root@jmnote ~]# for VALUE in "${ARR[@]}"; do echo "<---- $VALUE ---->"; done
<---- Filesystem           1K-blocks      Used Available Use% Mounted on ---->
<---- /dev/mapper/VolGroup00-LogVol00 ---->
<----                       27678892  18857720   7392488  72% / ---->
<---- /dev/xvda1              101086     36768     59099  39% /boot ---->
<---- tmpfs                   524288         0    524288   0% /dev/shm ---->
[root@jmnote ~]# echo ${ARR[0]}
Filesystem           1K-blocks      Used Available Use% Mounted on
[root@jmnote ~]# echo ${ARR[1]}
/dev/mapper/VolGroup00-LogVol00

3 같이 보기

4 참고 자료

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