我正在尝试将'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”的错误信息。
发布于 2014-02-22 20:26:56
在shell编程中,if
中的括号必须用空格分隔:
if ["$i" -gt "$count"]; then
必须是:
if [ "$i" -gt "$count" ]; then
左方括号([
)实际上是一个内置的外壳命令,因此需要后面的空格来从参数中对其进行分隔,就像任何命令一样。
https://stackoverflow.com/questions/21954286
复制相似问题