shell脚本编程-循环(for、while、until)
for命令格式: – list参数:迭代中要用的一系列值 – 每个迭代中,变量var会包含列表中的当前值 – do和done语句之间输入的命令可以是一条或多条标准的bash shell命令 1 2 3 4 for var in list do commands done 读取列表中的值 for命令最基本的用法就是遍历for命令自身中定义的一系列值: 在最后一次迭代后,$test变量的值会在shell脚本的剩余部分一直保持有效,除非修改它 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 $cat test #!/bin/bash for test in Alabama Alaska Arizona Arkansas California Colorado do echo The next state is $test done echo "The last state we visited was $test" test = Connecticut echo "Wait , now we're visiting was $test" $ . / test The next state is Alabama The next state is Alaska . . . The last state we visited was Colorado wait ,