Linux Shell Scripting: Error with my .sh file

#!/bin/sh
$x="Hello";
$y="World";
echo $x $y;

Open in new window

couchdbsite.sh: line 2: =Hello: command not found
couchdbsite.sh: line 3: =World: command not found
LVL 16
hankknightAsked:
Who is Participating?
 
simon3270Connect With a Mentor Commented:
Drop the $ from the start of  lines 2 and 3.

You *set* a variable with
   name=value
the *use* the variable with
   $name
0
 
simon3270Commented:
To explain, if you use a variable which has not been set, the shell replaces the variable with the empty string.  it also swallows quotes, so
    $x="Hello";
is processed to
    =Hello

Again, note that ";" is not a command *terminator* - you don't need it (and shouldn't use it) at the end of lines.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.