2015-02-09 53 views
0

我有以下bash脚本:简单Shell/bash程序语法

#!/bin/bash 
if [ ! -f numbers ]; then echo 0 > numbers; fi 
count = 0 
while [[$count != 100]]; do 
count = `expr $count + 1` 
done 

当我在我的Mac上运行它在终端,我得到以下的输出:

seq_file_gen.sh: line 3: count: command not found 
seq_file_gen.sh: line 4: [[: command not found 

为什么我收到这些错误?这个脚本是我的老师给我的,所以我不知道为什么我不能让这个脚本运行。任何帮助将不胜感激。

编辑: 这是写这个剧本(含空格)

#!/bin/bash 
if [ ! -f numbers ]; then echo 0 > numbers; fi 
count=0 
while [[ $count != 100 ]]; do 
count=`expr $count + 1` 
done 
+0

投票?在不投票的情况下提出基本问题似乎是不可能的。 – dhint4 2015-02-09 20:18:15

+1

Do * not *在等号周围使用空格:写入'count = 0'和'count =''expr $ count + 1''。我没有申请downvote,但我想这可能是因为这些是从阅读文档确定的基本shell语法问题。 – lurker 2015-02-09 20:24:23

+1

你还没有'100]]'中的空间,第2行的'数字'是什么?这甚至是一个完整的脚本? – guessimtoolate 2015-02-09 20:25:20

回答

1

前添加空格/ [[后的正确途径和]]像这样:什么是对的原因

while [[ $count != 100 ]]; do 
+0

感谢您的回应,它的工作原理:-) – dhint4 2015-02-09 20:21:42