Shell for while 循环
Posted 心流灬灬
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Shell for while 循环相关的知识,希望对你有一定的参考价值。
1 li@ubuntu:~/test$ cat a.sh
2 #!/bin/bash
3
4 for loop in 1 2 3 4 5
5 do
6 echo "The value is : $loop"
7 done
8
9 echo
10
11 for str in This is a string
12 do
13 echo $str
14 done
15
16 echo
17
18 for file in $HOME/.bash*
19 do
20 echo $file
21 done
22
23 li@ubuntu:~/test$ ./a.sh
24 The value is : 1
25 The value is : 2
26 The value is : 3
27 The value is : 4
28 The value is : 5
29
30 This is a string
31
32 /home/li/.bash_history
33 /home/li/.bash_logout
34 /home/li/.bashrc
35 li@ubuntu:~/test$
while:
1 li@ubuntu:~/test$ cat t.sh
2 #!/bin/bash
3
4 while read number
5 do
6 echo "The number is $number"
7 done
8 li@ubuntu:~/test$ ./t.sh
9 5
10 The number is 5
11 4
12 The number is 4
13 9
14 The number is 9
15 8
16 The number is 8
17 2
18 The number is 2
19 ^C
20 li@ubuntu:~/test$
以上是关于Shell for while 循环的主要内容,如果未能解决你的问题,请参考以下文章
Shell编程Shell中for循环while循环until循环语句
Shell编程Shell中for循环while循环until循环语句