Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
334 views
in Technique[技术] by (71.8m points)

bash shell nested for loop

I want to write a nested for loop that has to work in the bash shell prompt. nested for loop in Single line command.

For example,

for i in a b; do echo $i; done
a
b

In the above example, for loop is executed in a single line command right. Like this I have tried the nested for loop in the shell prompt. Its not working. How to do this. Please update me on this.

question from:https://stackoverflow.com/questions/4847854/bash-shell-nested-for-loop

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The question does not contain a nested loop, just a single loop. But THIS nested version works, too:

# for i in c d; do for j in a b; do echo $i $j; done; done
c a
c b
d a
d b

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...