带变量的支撑扩展? [英] Brace expansion with variable?

查看:28
本文介绍了带变量的支撑扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#!/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 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆