"STR: Command not found" while assigning a value to a variable
I entered the following lines into a shell script called “test.sh”:
#!/bin/bash
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?
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
U+0022 ‹"› \N{QUOTATION MARK}
While yours are:
$ uniprops '”' | head -1
U+201D ‹”› \N{RIGHT DOUBLE QUOTATION MARK}
So, just use regular quotes and you'll be fine:
#!/bin/bash
echo Hello World
STR="Hello Again"
echo "$STR" ## Get into the habit of ALWAYS quoting your variables as well