for循环语法及for循环脚本例子
在shell里for循环常用于执行有限次数的循环,而while一般才用于守护进程无限循环等等
语法:
i:变量名
words:变量取值范围
command:命令
for i in words; do
#command
done
现学现用,我们用for循环简单写一个显示当前目录下的文件脚本:
words=`ls /root/`
for i in words; do
echo $i
done
[root@node1]# sh test.sh
anaconda-ks.cfg
bootime.svg
git_test
monitor
null
完成!