Solved

Linux Shell Scripting: Error with my .sh file

Posted on 2013-11-08
2
164 Views
Last Modified: 2013-11-08
#!/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
0
Comment
Question by:hankknight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 19

Accepted Solution

by:
simon3270 earned 500 total points
ID: 39633534
Drop the $ from the start of  lines 2 and 3.

You *set* a variable with
   name=value
the *use* the variable with
   $name
0
 
LVL 19

Expert Comment

by:simon3270
ID: 39633542
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

Featured Post

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question