일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- ubuntu
- Ansible
- Docker
- cephadm
- archlinux
- HTML
- ceph
- repository
- pacman
- grafana-loki
- terraform
- i3
- cloud-init
- kolla
- awx
- KVM
- k8s
- Kubernetes
- Octavia
- Linux
- Kubeflow
- libvirt
- kolla-ansible
- golang
- yum
- OpenStack
- ceph-ansible
- port open
- nfs-provisioner
- Arch
Archives
- Today
- Total
YJWANG
Bash while-read 구문 (변수 2가지 이상일 때 loop문 사용) 본문
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
반응형