Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Linux Shell Scripting: Error with my .sh file

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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

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.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

927 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