[GRASS-user] run commands sequentially - help please

Scott Mitchell smitch at mac.com
Thu Aug 3 13:48:15 EDT 2006


On 3-Aug-06, at 12:57, Sampson, David wrote:

> Scott,
>
>
> BTW I remember Markus showing us a way to save commands you type to  
> the GRASS CLI into a script (think is was X.save where  
> X=something).. this is good if you want to perform it once in  
> geenral and then edit the script for variations. Couldn't find it  
> off hand in the docs.
>
If you're using the command line, then you're just using a UNIX  
shell, customized to be able to run the GRASS modules.  UNIX shells  
tend to have their own history mechanisms, so we just take advantage  
of that.  If I remember correctly, the GRASS startup fires up the  
bash shell, and manipulates this to store the history during GRASS  
sessions into the mapset directory (in a .bash_history file).  So you  
can actually go find that file (it's just a text file) and look in it  
to see what has been entered - you can also use the bash history  
command - try typing that in from the GRASS prompt, and you should  
see a list of everything you've been doing.  You can also redirect it  
to a file.  Lots of possibilities - not sure which way was shown to  
you, but just looking in $MAPSET/.bash_history and extracting the  
part you want is simple enough.

>
> I'd be interested to know if you could set and use variables in the  
> approach we used bellow. I never tried.  but if you could say use  
> output=$OUTMAP and input=$INMAP and then you can loop for a series  
> of maps. and the input and output are auto generated based on the  
> basefile name.
>
> Can someone provide a sample snippet of how this might look?
>
> Would the for loop be part of the said script, or would you call  
> one script from another passing variables?
>
> This might be good if it is a repeated process you will use ALOT...  
> a type of mild automation.
>

Definitely.  I see now that at least one example is already posted.   
You may be interested in the BASH scripting guide at http:// 
www.tldp.org/LDP/abs/html/

>
> I notice that in grass 6.1 there is lots of information in the  
> OUTPUT window of what is passed from the command... can you capture  
> this?.. I have not tried any of the icons....  if so then this is  
> another way to maybe build your script.  I'm likin 6.1 more and more
>

There is a way to get at it in the GUI I'm told, but I still keep  
using the command line myself...

>
> Just some thoughts.
>
>
>
> From: Scott Mitchell [mailto:smitch at mac.com]
> Sent: August 3, 2006 12:47
> To: Sampson, David
> Cc: Tiago Salgueiro; grassuser at grass.itc.it
> Subject: Re: [GRASS-user] run commands sequentially - help please
>
>
> A few elaborations that might help unix-newbies:
>
> On 3-Aug-06, at 12:25, Sampson, David wrote:
>
>> Dirty approach,
>>
>> I used this approach when doing mass imports of files and only had  
>> slight variations.
>>
>> under linux (shoudl work too in cygwin, dos batch would achieve  
>> the same thing)
>>
>> I created a script file (executable text Basicaly) that for you  
>> would look like
>>
>> # for a script named runme.sh
>> #(what ever header you need for your shell)
>> #!/bin/sh
>>
>
> Putting $!/bin/sh at the top of a script will ensure that the file  
> gets interpreted by whatever the default shell is on the system.   
> Forcing other shells is also possible here, but using just "sh"  
> means you get the default (i.e. as opposed to bash, csh, tcsh, ksh,  
> etc etc).
>
>>
>> v.in.asci (string of settings);
>
> note that should be ascii with two i's
>
>> g.region (string of settings);
>> v.surf.rst (string of settings);
>> nviz (string of settings);
>>
>> #end of script
>>
>> then at the $prompt  you need to make the file executable
>> $chmod 777 runme.sh
>
> Note this makes the file readable, writeable and executable to  
> everyone on the system.  If this is just your own private linux or  
> windows box, you probably don't care, but if someone is doing this  
> on a multi-user system, you might not want other people to be able  
> to edit your files.  Using chmod 755 would make it readable and  
> executable to anyone, but only writeable to you, the owner of the  
> file.  An alternative, more user-friendly syntax is
>
> chmod u+x runme.sh
>
> which simply says add the execute permission ("+x") for the User  
> ("u") that owns runme.sh
>
>>
>> then at the $prompt inside a GRASS session you can run the file
>> $./runme.sh
>>
>> boom!
>>
>> notice in the script that each line ends in a ; (semi-colon) this  
>> separates each command
>
> I don't think you need that.  It's C syntax to do that, not needed  
> in a shell script unless you're concatenating multiple commands on  
> to a single line.
>
>>
>> Note also that sometimes options need to be in quotes
>> eg
>> v.in.ascii option1="settings string that may contain escape  
>> characters or spaces";
>>
>> Alternatively you can capture what you enter at the CLI using
>>
>>
>>
>>
>> From: grassuser-bounces at grass.itc.it [mailto:grassuser- 
>> bounces at grass.itc.it] On Behalf Of Tiago Salgueiro
>> Sent: August 3, 2006 11:24
>> To: grassuser at grass.itc.it
>> Subject: [GRASS-user] run commands sequentially - help please
>>
>> Hi all,
>>
>>
>>
>> First of all you should know that I’m a beginner using GRASS.
>>
>>
>>
>> I want to create a 3D map from a text file with coordinates. I  
>> think the commands I will need are the following:
>>
>>
>>
>> 1 - v.in.ascii
>>
>> 2 - g.region
>>
>> 3 - v.surf.rst
>>
>> 4 – nviz
>>
>>
>>
>> But I don’t want to write the commands every time I want to see a  
>> map. So I desire to do this sequentially. How can I do that? This  
>> way I’ll only need to run one command and the map happens.
>>
>>
>>
>> Thanks for your help.
>>
>>
>>
>>
>>
>> Cumprimentos/Best Regards,
>>
>>
>>
>> Tiago Salgueiro
>>
>>
>>
>> _______________________________________________
>> grassuser mailing list
>> grassuser at grass.itc.it
>> http://grass.itc.it/mailman/listinfo/grassuser
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/grass-user/attachments/20060803/2641ede6/attachment.html


More information about the grass-user mailing list