Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

I tried the following:

#!/bin/bash
NUM = 0
echo Number $NUM > text.txt

but I get the following error:

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

share|improve this question
up vote 12 down vote accepted

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

Remove the whitespaces:

NUM=0

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:

number=0
share|improve this answer
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 2 days ago

Don't use spaces in line NUM=0

share|improve this answer

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

#!/bin/bash
NUM=0
echo $NUM > text.txt
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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