I entered the following lines into a shell script called “test.sh”:

echo Hello World
STR=”Hello Again”
echo $STR

After chmod to executable, I ran the script with ./test.sh. However, I get the message

./test.sh: line 3  STR: Command not found

What am I doing wrong?

  • 1
    Did terdon's answer solve your question? If not it could be that you accidentally have spaces around your variable assignment.
    – Arronical
    Jul 5 '16 at 9:38
  • @Voker just an stylistic comment based on my suggestion: I think it is best to use Blockquote for error messages instead of Code block; at the end, this is not code but some text the Bash interpreter is returning.
    – fedorqui
    Jul 5 '16 at 12:23
  • @fedorqui why? Quote blocks don't preserve formatting, they interpret special characters (e.g. *,_, #) as markdown, and are rendered differently by screen reader software. I think that anything that is either given or received by a computer should be in code blocks. You never know when the exact format can be relevant. Especially when dealing with things like this where unicode comes into play.
    – terdon
    Jul 6 '16 at 11:24
  • @terdon it really depends on cases and there is even a request to Add format for logs/warnings/error messages which allows word-wrapping and preserves newlines. To me, if it is just a line like this case, I prefer quote blocks since it makes it easier to understand what is code and what is errors.
    – fedorqui
    Jul 6 '16 at 11:42
  • @fedorqui I guess we should take it to meta but I always prefer fixed-width font and exact format reproduction whenever posting a message that is either read or produced by a computer.
    – terdon
    Jul 6 '16 at 11:57

What are you using to create that script? The quote characters you have in your question are wrong. They're not regular double quotes (") but . The regular quotes are:

$ uniprops '"' | head -1

While yours are:

$ uniprops '”' | head -1

So, just use regular quotes and you'll be fine:

echo Hello World
STR="Hello Again"
echo "$STR" ## Get into the habit of ALWAYS quoting your variables as well
  • Thanks for the reply Terdon. The double quotes in the file are correct, The post was from an email.
    – Jay Silver
    Jul 5 '16 at 9:20
  • 1
    uniprops looks cool. I found the page (is that our own tchrist?). Do I have to download it from source, or is it available in a package manager somewhere? E: Unable to locate package uniprops
    – TRiG
    Jul 5 '16 at 13:57
  • 1
    I don't use Perl much (barely at all). I just want to know more than the minimum about Unicode.
    – TRiG
    Jul 5 '16 at 14:52
  • 1
    @TRiG well, in Ubuntu, it's as simple as sudo apt-get install cpanminus; sudo cpanm Unicode::Tussle and then you have the uniprops command. Of course, tchrist wrote the damn thing so you may as well ask him in chat :)
    – terdon
    Jul 5 '16 at 14:56
  • 1
    I regretfully run into this sort of nonsense all the time. A particular wiki system at my employer seems to have a nasty habit of translating hyphen-minus - U+002D into hyphen U+2010 (or similar). Then things like uname ‐a stop working :-/. Email clients often have similar nefarious habits - especially when using HTML formatting - another good reason to prefer plain-text emails. Jul 5 '16 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.