echo variable returns blank

3171 views shell
-5

Hi I am new to shell scripting and currently following www.shellscript.sh tutorial on variables part 1. However, the script does not seem to echo the assigned value of the variable but a blank instead. Here is my script:

#!/bin/sh
My_MESSAGE="Hello World"
echo $MY_MESSAGE

I have seen similar questions and having trouble understanding the answers. Can someone kindly tell me how do I resolve this?

answered question

Gladly, Linux/UNIX is case dependant. it should be echo $My_MESSAGE.

I have tried: "$MY_MESSAGE" as mentioned by others while googling but that too does not seem to work.

Oh i just noticed it thank you for informing me

There is no such thing as "Unix/Linux scripting", see e.g. the description of the "shell" tag that you applied. Since you are using a very specific shell, that should be included as tag, since each shell has its own syntax. Also, that syntax is independent from the OS underneath.

1 Answer

1

You've spelt the variable wrong. Variables are case sensitive:

#!/bin/sh
MY_MESSAGE="Hello World"
echo $MY_MESSAGE

posted this

Have an answer?

JD

Please login first before posting an answer.