#!/bin/sh for i in {1..5} do echo "Welcome" done
会工作,显示欢迎5次.
#!/bin/sh howmany=`grep -c $1 /root/file` for i in {1..$howmany} do echo "Welcome" done
不行! howmany将等于5,因为grep -c的输出将显示. $1是运行脚本时具体的参数1.
有任何想法吗?
创建一个序列来控制你的循环
for i in $(seq 1 $howmany); do echo "Welcome"; done