I don't know how to use variables for further executing in a script.

I tried the following:

NUM = 0
echo Number $NUM > text.txt

but I get the following error:

num.sh: 3: num.sh: NUM: not found

3 Answers 3


There must not be any whitespace around = in variable declaration in shell.

Remove the whitespaces:


Also if you don't have any good reason, don't use all uppercases for a user defined shell variable name as there is chance that this could conflict with any environment variable.

Better do:

  • 6
    +1 for lower case variables. I've heard seasoned programmers - people much smarter than I am - saying that bash variables should always be upper case...
    – pfnuesel
    Nov 5, 2016 at 1:28

Don't use spaces in line NUM=0


You may need to remove the space after NUM , so the script should look like:

echo $NUM > text.txt

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .