<div dir="ltr"><div>Try remove spaces from r.sum command output (e.g. using `sed`) and since the results is </div><div><br></div><div>SUM=16116.500006</div><div><br></div><div>which is valid bash variable definition, you can use `eval` command which will define the variable, so you can use it afterwards.</div>

<div><br></div><div>$ eval $(echo "SUM = 16116.500006" | sed -e "s/ //g")</div><div>$ echo $SUM</div><div>16116.500006</div><div><br></div><div>I assume from what you have written that `<span style="font-family:arial,sans-serif;font-size:13px">r.sum rast=map@mapset` prints </span></div>

<div><br></div><div>SUM = 16116.500006<br></div><div><br></div><div>to standard output. Knowing what is the output of that module is crucial. What module is this, do you have documentation? GRASS modules (in GRASS distribution) use the convention that if you use `-g` flag they print the variables in "shell script style", so you can use the output in eval function or parse it easily. They output would be</div>

<div><br></div><div>SUM = 16116.500006<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jan 13, 2014 at 10:20 AM, BLANDENIER Lucien <span dir="ltr"><<a href="mailto:lucien.blandenier@unine.ch" target="_blank">lucien.blandenier@unine.ch</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello Vaclav,<br>
<br>
I tried with the following script:<br>
<br>
$C=$(r.sum rast=map@mapset)<br>
$echo $C<br>
SUM = 16116.500006<br>
<br>
<br>
But I think the variable C stores all the command (r.sum rast=map@mapset) and not only the result. Do you know how it would be possible to store the result "SUM = 16116.500006"<br>
<br>
<br>
Regards<br>
<br>
Lucien<br>
<br>
<br>
________________________________<br>
De : Vaclav Petras [<a href="mailto:wenzeslaus@gmail.com">wenzeslaus@gmail.com</a>]<br>
Envoyé : dimanche 12 janvier 2014 03:11<br>
À : BLANDENIER Lucien<br>
Cc : <a href="mailto:grass-user@lists.osgeo.org">grass-user@lists.osgeo.org</a><br>
Objet : Re: [GRASS-user] how to store results from r.sum with script<br>
<div class="im"><br>
Hi,<br>
<br>
I might missed it but I don't know about r.sum module. (I know only r.sun).<br>
<br>
Saving standard output of module (if it prints something to standard output) is the same as for any other command line tool in bash. If the output is a map (in GRASS) just use it as input to some other module (using the map name).<br>


<br>
Examples bellow show saving outputs of echo command to variables (echo command just print its parameters to standard output, i.e. to command line). Working with numbers (additions, multiplications) can be more difficult (requires different syntax) but there should be some online guides.<br>


<br>
Vaclav<br>
<br>
<br>
$ A="some text"<br>
$ echo $A<br>
some text<br>
<br>
$ B=`echo "this is printed to stdout"`<br>
$ echo $B<br>
this is printed to stdout<br>
<br>
$ C=$(echo "this is printed to stdout")<br>
$ echo $C<br>
this is printed to stdout<br>
<br>
(lines beginning with $ are lines with command which are meant to by typed into the command line, the other lines are output)<br>
<br>
<br>
</div><div class="im">On Sat, Jan 11, 2014 at 9:32 AM, BLANDENIER Lucien <<a href="mailto:lucien.blandenier@unine.ch">lucien.blandenier@unine.ch</a><mailto:<a href="mailto:lucien.blandenier@unine.ch">lucien.blandenier@unine.ch</a>>> wrote:<br>


Dear all,<br>
<br>
I would like to know if there is a way to store results of a calculation done with r.sum on many raster with a bash script.<br>
<br>
I need to reuse these results in later calculations.<br>
<br>
Thanks<br>
<br>
<br>
Lucien<br>
<br>
_______________________________________________<br>
grass-user mailing list<br>
</div><a href="mailto:grass-user@lists.osgeo.org">grass-user@lists.osgeo.org</a><mailto:<a href="mailto:grass-user@lists.osgeo.org">grass-user@lists.osgeo.org</a>><br>
<a href="http://lists.osgeo.org/mailman/listinfo/grass-user" target="_blank">http://lists.osgeo.org/mailman/listinfo/grass-user</a><br>
<br>
</blockquote></div><br></div>