for…in…do…done
格式
for var in val1 val2 val3
do
语句1
语句2
...
done
示例:
for i in a 2 cc
do
echo $i
done
for file in `ls`
do
echo $file
done
for i in $(seq 1 10)
do
echo $i
done
for i in {a..z}
do
echo $i
done
for ((…;…;…)) do…done
格式:
for ((expression; condition; expression))
do
语句1
语句2
done
示例:
for ((i=1; i<=10; i++))
do
echo $i
done
while…do…done
格式:
while condition
do
语句1
语句2
...
done
示例:
while read name
do
echo $name
done
until…do…done
格式:
until condition
do
语句1
语句2
...
done
示例:
until [ "${word}" == "yes" ] || [ "${word}" == "YES" ]
do
read -p "Please input yes/YES to stop this program: " word
done
死循环的处理方式
如果AC Terminal可以打开该程序,则输入Ctrl+c即可。
否则可以直接关闭进程:
使用top
命令找到进程的PID
输入kill -9 PID
即可关掉此进程