Elpezmuerto Elpezmuerto - 1 year ago 98
Linux Question

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,


howdy="Hello $USER !"
echo $howdy

However, when I execute the script (
) I get this:

howdy=Hello aaron!: Command not found.
howdy: Undefined variable.

What am I doing wrong?

Answer Source

You have two errors in you code:

  1. you are using sh syntax instead of csh one to set the variable
  2. you are not escaping the "!" character (history substitution)

Try this:


set howdy="Hello $USER \!"
echo $howdy
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download