r.mapcalc script and pipes

Malcolm Williamson malcolm at cast.uark.edu
Tue Jul 20 09:58:01 EDT 1993

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.
> 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?

Avoiding a direct answer (as I don't know that I have the definitive one!!),
here is how I deal with such problems:

echo "res = $ima "\*" $ima" > test
r.mapcalc < test

This kind of sequence can be easily looped, and, although it may become a bit
unwieldy, can be used to create quite complex scripts. Hope this helps!

Malcolm D. Williamson - Research Assistant       E-mail: malcolm at cast.uark.edu
Center for Advanced Spatial Technologies      Telephone: (501) 575-6159
Ozark Rm. 12                                        Fax: (501) 575-3846 
University of Arkansas              
Fayetteville, AR 72701

More information about the grass-dev mailing list