我有一个名为test.sh的脚本:
#!/bin/bash
STR = "Hello World"
echo $STR
Run Code Online (Sandbox Code Playgroud)
我跑的时候sh test.sh得到这个:
test.sh: line 2: STR: command not found
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?我在网上看一下非常基础/初学者的bash脚本教程,这就是他们说声明变量的方式......所以我不确定我做错了什么.
我在Ubuntu Server 9.10上.是的,bash位于/bin/bash.
有人能告诉我是否应该在shell脚本中包含变量的引号?
例如,以下是正确的:
xdg-open $URL
[ $? -eq 2 ]
Run Code Online (Sandbox Code Playgroud)
要么
xdg-open "$URL"
[ "$?" -eq "2" ]
Run Code Online (Sandbox Code Playgroud)
如果是这样,为什么?