Shell编程—结构化命令(2)
1 for 命令 for命令的基本格式: for var in list do commands done 在list参数中,你需要提供迭代中要用到的一系列值。 1.1 读取列表中的值 例子: $ vim test1 #!/bin/bash # testing the for variable after the looping 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 $test" 执行结果: $ ./test1 The next state is Alabama The next state is Alaska The next state is Arizona The next state is Arkansas The next state is California The next state is Colorado The last state we visited was Colorado Wait, now we're