在shell里for循环常用于执行有限次数的循环,而while一般才用于守护进程无限循环等等

语法:

i:变量名

words:变量取值范围

command:命令

for i in words; do    #commanddone

现学现用,我们用for循环简单写一个显示当前目录下的文件脚本:

words=`ls /root/`for i in words; do echo $idone[root@node1]# sh test.sh anaconda-ks.cfgbootime.svggit_testmonitornull

完成!