if [“$ i”-gt“$ count”];给人一种错误

时间:2014-02-22 12:25:31

标签: shell

我正在尝试将'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:第11行:[3570:命令未找到 '不断。

1 个答案:

答案 0 :(得分:4)

在shell编程中,if中的括号必须用空格分隔:

if ["$i" -gt "$count"]; then

必须:

if [ "$i" -gt "$count" ]; then

[编辑] 左括号([)实际上是一个内置的shell命令,因此需要后面的空格将其与参数分隔开,就像使用任何命令一样。< / p>

相关问题