Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Linux Shell Scripting: Error with my .sh file

Posted on 2013-11-08
2
Medium Priority
?
169 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 20

Accepted Solution

by:
simon3270 earned 2000 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 20

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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

715 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