Scripting custom variable declaration (csh shell)

I'm trying to learn shell scripts and try to create a user-defined variable in the script, first:

howdy="Hello $USER !"
echo $howdy

However, when I execute script ( ./first), I get the following:

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

What am I doing wrong?

+3
source share
3 answers

There are two errors in your code:

  • you use sh syntax instead of csh to set the variable
  • you do not avoid "!" symbol (history replacement)

Try the following:

#!/bin/csh

set howdy="Hello $USER \!"
echo $howdy
+8
source

cshexpects you to be setvariables. Try

set howdy="Hello $USER"
echo $howdy
+1
source

howdy=''Hello $USER !''

:

howdy="Hello $USER !"

, .

0

Source: https://habr.com/ru/post/1766987/


All Articles