matching 되게 for loop 쓰는 법

chmod777의 이미지

for x in 1 2 3 4 5 ;do
for y in 5 4 3 2 1 ;do
일 경우 결과는
x=1,y=5
x=1,y=4
x=1,y=3
x=1,y=2
x=1,y=1
x=2,y=5
x=2,y=4
x=2,y=3
x=2,y=2
x=2,y=1
... 이렇게 총 25개의 결과가 나오는데

저는
x=1,y=5
x=2,y=4
x=3,y=3
x=4,y=2
x=5,y=1
이렇게 5개의 결과가 나오기를 바랍니다..

ymir의 이미지

$ cat x
1
2
3
4
5
$ cat y
5
4
3
2
1
$ paste x y | while read -r x y; do echo "x=$x, y=$y"; done
x=1, y=5
x=2, y=4
x=3, y=3
x=4, y=2
x=5, y=1

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

ymir의 이미지

$ x=(1 2 3 4 5)
$ y=(5 4 3 2 1)
$ for ((i = 0; i < ${#x[@]}; i++)); do echo "x=${x[$i]}, y=${y[$i]}"; done
x=1, y=5
x=2, y=4
x=3, y=3
x=4, y=2
x=5, y=1

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』