Ubuntu – 可执行文件 – 脚本运行时的variables赋值抛出错误

我试图在Ubuntu的机器上运行一个小脚本 – testing。

具体如下:

var1 = bash var2 = /home/test/directory ... ... <some more variable assignments and then program operations here> ... ... 

现在每次运行它,都会引发错误:

 root@localhost#/opt/test /opt/test: line 1: var1: command not found /opt/test: line 3: var2: command not found ... ... more similar errors ... 

有人能帮我理解这个脚本中的错误吗?

非常感谢。

首先,您需要转义第一个string(第二个string作为path不需要转义)var1 =“Variable”第二,语法中不能有任何空格。 VAR2 = /这个/是/path/到/富

没有完整的图片很难看到你想做什么,但看起来像你使用shell脚本来调用python之前分配一些环境variables。 你需要把“#!/ bin / bash”(或者你想要的东西)放在你的文件的顶部。 运行“/ bin / bash scriptname”也可以,但不能保证。

你可能想看看那里的一些shell编程教程(Google是你的朋友)来指向正确的方向。