【发布时间】:2014-02-22 12:25:30
【问题描述】:
我正在尝试将 'f-$count'(f-1,f-2) 名称放入数组中。
下面是代码,
echo "Enter the count"
read count
echo $count
#arr=()
i=1
while true;
do
if ["$i" -gt "$count"]; then
exit 0
else
arr[$i]=f-$i
i=$((i+1))
fi
done
echo ${arr[@]}
我收到的错误是 'script.sh: line 11: [3570: command not found ' 连续。
【问题讨论】:
-
这在 BashPitfalls 页面中有介绍:mywiki.wooledge.org/BashPitfalls
-
仅供参考,如果您使用 bash 或其他现代 ksh 衍生工具(显然是,因为您的代码使用数组),则此比较的现代/首选语法是
if (( i > count )); then。
标签: shell