[GRASS-dev] Using a multi-"${GIS_OPT_X}" input in a shell for loop
Glynn Clements
glynn at gclements.plus.com
Wed Nov 13 07:50:27 PST 2013
Hamish wrote:
> Nikos wrote:
> >> for Image in `echo $GIS_OPT_MSX | tr "," "\ "` ; do echo ${Image} ; done
>
> Curly brackets do nothing to protect the contents of a variable. Using them
> tricks new bash coders into thinking they are protected when they are not.
> To avoid propagating the damaging myth, only use them when you actually need
> them (eg to protect the variable name from following characters, not its contents).
In case it wasn't clear: putting the variable name in braces prevents
subsequent alphanumeric characters from being interpreted as part of
the variable name; e.g.
echo ${hello}_world
will substitute the value of the variable "hello", whereas
echo $hello_world
will substitute the value of the variable "hello_world".
But if you want to prevent the substituted value from being re-parsed,
double quotes must be used, e.g.:
echo "$hello"
Example:
$ hello='hi there'
$ echo $hello
hi there
$ echo "$hello"
hi there
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list