[GRASS-dev] Using a multi-"${GIS_OPT_X}" input in a shell for loop

Vaclav Petras wenzeslaus at gmail.com
Wed Nov 13 08:47:19 PST 2013


On Wed, Nov 13, 2013 at 10:50 AM, Glynn Clements
<glynn at gclements.plus.com>wrote:

>
> 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
>
> I remember that we had this conversation recently. What about putting some
(ba)sh(ell) primer into the manual?

However, I must say the same I said before. If you need some advanced bash
functionality such as `if` and `for` or even functions it is better to
use/learn Python instead.

--
> Glynn Clements <glynn at gclements.plus.com>
> _______________________________________________
> grass-dev mailing list
> grass-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20131113/1c92efcf/attachment.html>


More information about the grass-dev mailing list