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
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityThere 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
You may need to remove the space after NUM
, so the script should look like:
#!/bin/bash
NUM=0
echo $NUM > text.txt