GRASS GIS Loop – How to Do the Loop When Using GRASS Module r.water.outlet

grassgrass.scriptwatershed

I have seen this post:Watershed Analysis with GRASS, and I have a .txt file which contains coordinates of many points, and I want to use r.water.outlet to get basin area of each point.

I type the following code in the post:

while read X Y; do
.... ;
done < cross_pts.txt

and in GRASS command line, it shows:

enter image description here

I already import the DEM file and successfully run r.watershed to get the drainage file in GRASS, but I do not know how to follow the guide in the post.

I am new to using command line and know nothing about bash script. How can I loop through all different coordinates? I am using GRASS 6.4.3 under windows8.

Best Answer

It looks like you're running GRASS using the default Windows shell. The loop code you posted is for a UNIX-like shell, and the Windows shell doesn't understand it. You have two options:

Use the Windows shell commands for all of your batch processing. This question/answer might help (although I've not done it myself): https://stackoverflow.com/questions/155932/how-do-you-loop-through-each-line-in-a-text-file-using-a-windows-batch-file

Or you could use a UNIX-like shell on Windows. I think that msys/mingw comes with the OSGeo4W installer so you probably already have it installed. In the command prompt you have there try typing "sh" (to start the new shell) and try your command again). If that doesn't work, try starting msys from the Start menu and starting GRASS from that shell.