90.Programming
Bash while-read 구문 (변수 2가지 이상일 때 loop문 사용)
왕영주
2020. 11. 4. 21:36
Bash에서 while loop에 read 구분을 같이 사용하면
변위가 두 가지 이상 필요할 때 유용하게 사용할 수 있다.
==> test2.sh <==
#!/bin/bash
cat << EOF > text.txt
a b
c d
e f
EOF
while read a b
do
echo "$a and $b"
done < text.txt
## Output
# [yjwang@yjwang ~]$ /bin/bash test2.sh
# a and b
# c and d
# e and f
==> test.sh <==
#!/bin/bash
read -d '' text << EOF
1 2
3 4
5 6
EOF
while read a b
do
echo "$a $b"
done < <(echo "$text")
## Output
# [yjwang@yjwang ~]$ /bin/bash test.sh
# 1 2
# 3 4
# 5 6
반응형