[英]Declaring User Defined Variable in Shell Scripting (csh shell)
I am trying to learn shell scripting and trying to create a user defined variable within the script, first
: 我正在尝试学习shell脚本并尝试在脚本中创建用户定义的变量,
first
:
howdy="Hello $USER !"
echo $howdy
However, when I execute the script ( ./first
) I get this: 但是,当我执行脚本(
./first
)时,我得到了这个:
howdy=Hello aaron!: Command not found.
howdy: Undefined variable.
What am I doing wrong? 我究竟做错了什么?
You have two errors in you code: 您的代码中有两个错误:
Try this: 试试这个:
#!/bin/csh
set howdy="Hello $USER \!"
echo $howdy
csh
expects that you set
variables. csh
期望你set
变量。 Try 尝试
set howdy="Hello $USER"
echo $howdy
You are doing 你在做
howdy=''Hello $USER !''
You need to enclose the string in double quotes as: 您需要将字符串括在双引号中:
howdy="Hello $USER !"
You seem to be using two single quotes in place of a double quote. 您似乎使用两个单引号代替双引号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.