1
我想运行一个shell脚本。shell脚本:语法错误
的前两行是像如下:
#!/bin/bash
gr = (file1 file2 file3)
然而,当我运行该脚本,我得到以下错误: fileName.sh:2:语法错误: “(” 意外
我不习惯写这种类型的脚本,但我读了括号用于分组...
我不明白我做了什么错?
我想运行一个shell脚本。shell脚本:语法错误
的前两行是像如下:
#!/bin/bash
gr = (file1 file2 file3)
然而,当我运行该脚本,我得到以下错误: fileName.sh:2:语法错误: “(” 意外
我不习惯写这种类型的脚本,但我读了括号用于分组...
我不明白我做了什么错?
尝试这样做来创建一个数组:
gr=(file1 file2 file3)
在所有类型的变量赋值中都不允许有空格。
我试过了你的程序,我得到了同样的错误。
[[email protected] ~]$ sh fileName.sh
fileName.sh: line 2: syntax error near unexpected token `('
fileName.sh: line 2: `gr = (file1 file2 file3)'
我只是改变了这样的程序:
[[email protected] ~]$ cat fileName.sh
#!/bin/bash
gr=(file1 file2 file3)
而且问题消失。
[[email protected] ~]$ vi fileName.sh
我刚刚删除了空格,但同样的错误仍然存在... – bigTree
@bigTree确保您正在运行'bash'。尝试使用'bash script.sh',而不是用'sh script.sh'或'。/ script.sh'运行它。 – konsolebox
@konsolebox我的不好,现在它的作品谢谢!你能告诉我有什么区别吗? (谢谢!) – bigTree