$a="bar" ought to give you an error message saying
bash: foo=bar: command not found
a to the string
a="bar". Notice that
$a is the value of the variable
a, and that
$a="bar" is nonsensical.
If you want to change the value each time you run the script, you can do two things (at least).
a an environment variable. This mean that you set
a outside of the script and
Then you run your script as usual (it would need to be modified to not overwrite the value of
a inherited from the environment first). You could also use
to set the variable for the script only (i.e., not making it a variable in the calling shell).
Make the script take the value from the command line, so that you call the script like
The script would then do
to set the value of
a from the command line argument. Here,
$1 means "the first command line argument".
Whichever way you go about doing this, you may also want to check that the value
"$a" is sane (i.e. contains valid data) before using it.