相关疑难解决方法(0)

用变量支撑扩展?

#!/bin/sh
for i in {1..5}
do
   echo "Welcome"
done
Run Code Online (Sandbox Code Playgroud)

会工作,显示欢迎5次.

#!/bin/sh
howmany=`grep -c $1 /root/file`
for i in {1..$howmany}
do
   echo "Welcome"
done
Run Code Online (Sandbox Code Playgroud)

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.

Any ideas?

variables syntax bash variable-expansion

16
推荐指数
5
解决办法
6483
查看次数

标签 统计

bash ×1

syntax ×1

variable-expansion ×1

variables ×1