10

I found a nifty little shell script that I wanted to use from this website here. I have followed everything step-by-step, but receive the following error when running this on my CentOS box.

./deploy: line 3: =: command not found

Line 3 only contains...

$ERRORSTRING = "Error. Please make sure you've indicated correct parameters"

I've tried toying around with a bit, but don't understand why it won't accept the "=" character. Is there something wrong with the script, or is it merely something different in the way that my server processes the script?

Mateen Ulhaq
27.6k21 gold badges120 silver badges154 bronze badges
asked Apr 14, 2014 at 16:48
5
  • 5
    There are spaces around the = sign. Read the corresponding line as $ERRORSTRING="Error. Please make sure you've indicated correct parameters" with no spaces around the = sign. Commented Apr 14, 2014 at 16:52
  • 2
    (1) Remove spaces around =. (2) When assigning a variable, don't use $ (on the LHS). Commented Apr 14, 2014 at 16:52
  • ERRORSTRING="Error. Please make sure you've indicated correct parameters" Commented Apr 14, 2014 at 16:53
  • 1
    Don't copy scripts from anywhere without verifying its effectiveness. Commented Apr 14, 2014 at 16:53
  • Thank you all for the assistance -- I'm good to go now. :-) Devnull's answer was correct. Commented Apr 14, 2014 at 16:57

2 Answers 2

23

Gah, that script is full of bad scripting practices (in addition to the outright error you're running into). Here's the outright error:

$ERRORSTRING = "Error. Please make sure you've indicated correct parameters"

As devnull pointed out, this should be:

ERRORSTRING="Error. Please make sure you've indicated correct parameters"

A couple of lines down (and again near the end), we have:

echo $ERRORSTRING;

...which works, but contains two bad ideas: a variable reference without double-quotes around it (which will sometimes be parsed in unexpected ways), and a semicolon at the end of the line (which is a sign that someone is trying to write C or Java or something in a shell script). Use this instead:

echo "$ERRORSTRING"

The next line is:

elif [ 1ドル == "live" ]

...which might work, depending on whether the value of 1ドル has spaces, or is defined-but-blank, or anything like that (again, use double-quotes to prevent misparsing!). Also, the == comparison operator is nonstandard -- it'll work, because bash supports it in its [ ... ] builtin syntax, but if you're counting on having bash extensions available, why not use the much cleaner [[ ... ]] replacement? Any of these would be a better replacement for that line:

elif [ "1ドル" = "live" ]
elif [[ 1ドル == "live" ]]
elif [[ "1ドル" == "live" ]]

Personally, I prefer the last. The double-quotes aren't needed in this particular case, but IMO it's safest to just double-quote all variable references unless there's a specific reason not to. A bit further down, there's a elif [ 2ドル == "go" ] that the same comments apply to.

BTW, there's a good sanity-checking tool for shell scripts at www.shellcheck.net. It's not quite as picky as I am (e.g. it doesn't flag semicolons at the ends of lines), but it pointed out all of the actual errors in this script...

answered Apr 14, 2014 at 17:33
6

"Devnulls" answer was correct -- I had to remove the spaces around the "=" and remove the "$" from that line as well. The end result was...

ERRORSTRING="Error. Please make sure you've indicated correct parameters"

I've upvoted Devnull and gniourf_gniourf's comments.

Thank you to all whom have assisted!

answered Apr 14, 2014 at 17:05
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.