在Shell脚本中声明用户定义的变量(csh shell)

Elp*_*rto 5 linux shell csh

我正在尝试学习shell脚本并尝试在脚本中创建用户定义的变量first:

howdy="Hello $USER !"
echo $howdy
Run Code Online (Sandbox Code Playgroud)

但是,当我执行脚本(./first)时,我得到了这个:

howdy=Hello aaron!: Command not found.
howdy: Undefined variable.
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

and*_*coz 9

您的代码中有两个错误:

  1. 您使用sh语法而不是csh one来设置变量
  2. 你没有逃脱"!" 人物(历史替代)

试试这个:

#!/bin/csh

set howdy="Hello $USER \!"
echo $howdy
Run Code Online (Sandbox Code Playgroud)