6

I am trying to learn shell scripting and trying to create a user defined variable within the script, first:

howdy="Hello $USER !"
echo $howdy

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

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

What am I doing wrong?

4
  • What shell flavor? bash, ksh, zsh, ... ? Commented Sep 28, 2010 at 15:02
  • I didn't know it mattered but it is csh Commented Sep 28, 2010 at 15:04
  • 3
    Here's an indication how much it matters: Csh Programming Considered Harmful. Commented Sep 28, 2010 at 15:25
  • Each shell has its own language, with its own syntax. Commented Sep 28, 2010 at 15:28

3 Answers 3

13

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:

#!/bin/csh

set howdy="Hello $USER \!"
echo $howdy
Sign up to request clarification or add additional context in comments.

Comments

1

csh expects that you set variables. Try

set howdy="Hello $USER"
echo $howdy

Comments

0

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.

1 Comment

That was typo when putting it into stack overflow, sorry

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.