r.mapcalc script and pipes

Michael Shapiro shapiro at zorro.cecer.army.mil
Wed Aug 4 21:43:07 EDT 1993

In <9307200041.AA08840 at Jasper.Stanford.EDU> lobo at Jasper.Stanford.EDU (Agustin Lobo) writes:

>If I type
>set ima = vegetation1
>r.mapcalc res = $ima * $ima

>r.mapcalc works without problems, but if I type
>r.mapcalc < test

>where test is a file whose only line is:
>res = $ima * $ ima

>then r.mapcalc says <$ima> not found, that is, it does not interpret
>$ima as the value of ima. If I write test as,
>'res = ' $ima '*' $ima

>then r.mapcalc gets confused and me too.

Your confusion has do do with Unix. r.mapcalc knows nothing about
the $. Unix changes $ima to vegetation1 and r.mapcalc sees vegetation1,
not $ima. This only happens if Unix sees the $ which it will if you
put the expression on the command line. But if you put it into a file
and then send the file into r.mapcal (r.mapcalc < test) Unix doesn't
look into the file and substitute vegetation1 for $ima so r.mapcalc
sees $ima and gets confused (and you too).

You will have to learn some shell programming - but you can look
at shade.rel.sh for an example of how you might do what you want to do.

>I have to use this piping because r.mapcalc is within a loop in an
>script, ima takes different values and the expression actually passed
>to r.mapcalc is complex.
>Is there any way to get r.mapcalc to interpret $ima when piped?

Michael Shapiro               shapiro at zorro.cecer.army.mil
U.S. Army CERL                (217) 373-7277
P.O. Box 9005 
Champaign, Ill. 61826-9005

More information about the grass-dev mailing list