在 shell 脚本中找不到命令

sun*_*leo 5 shell-script variable

请告诉我为什么我无法打印变量值。

# chmod 777 chkscript.sh
# ./chkscript.sh
Run Code Online (Sandbox Code Playgroud)

chkscript.sh文件内容

variable = "This is variable"

echo "$variable"

echo "Hello World "
Run Code Online (Sandbox Code Playgroud)

输出 :

# ./chkscript.sh
./chkscript.sh: line 5: variable: command not found

Hello World
#
Run Code Online (Sandbox Code Playgroud)

PS: 有时

 variable1 = "/home/files" --- which is location if I try to print nothing gets printed.
 echo "$variable"
Run Code Online (Sandbox Code Playgroud)

D_B*_*Bye 13

在 shell 中,=变量赋值中的两边都不允许有空格。

试试这个:

variable="This is a variable"
Run Code Online (Sandbox Code Playgroud)

如果在 之前留一个空格=,shell 会将其前面的标记解析为命令或函数名称,这就是您看到“未找到命令”消息的原因。