括号扩展与变量? [英] Brace expansion with variable?
本文介绍了括号扩展与变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#!/bin/sh
for i in {1..5}
do
echo "Welcome"
done
会的工作,显示欢迎5次。
Would work, displays Welcome 5 times..
#!/bin/sh
howmany=`grep -c $1 /root/file`
for i in {1..$howmany}
do
echo "Welcome"
done
没有工作...的howmany就等于5因为这是grep的-c文件/根/文件的输出将显示。 $ 1参数1运行脚本时,这是特定的。
Doesn't work... howmany would equal 5 as that is what the output of grep -c file /root/file would display. $1 is parameter 1 which is specific when running the script.
任何想法?
推荐答案
创建一个序列来控制你的循环
create a sequence to control your loop
for i in $(seq 1 $howmany); do
echo "Welcome";
done
这篇关于括号扩展与变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文