[GIS] How to run OSgo4W shell script on Windows

gdalosgeoshell

I have a lot of DEMs that I want to use to create hillshades, slopes and color relief from and would like to automate the processes using a shell script within OSgeo4W shell. Here is the code I used within the shell script to automate the creation of hillshades.

for f in *.tif
do
  echo "Processing $f"
gdaldem hillshade $f $f-hillshade" -z 1.0 -s 1.0 -az 315.0 -alt 45.0 -compute_edges -of GTiff
done

I'm new to OSgeo4W and shell scripting. I'm working off this example as a starting point. When I call the shell script within the OSgeo4W I get an error message that Windows can't open the file and then it gives me an option to use the web to find the correct program or to manually select a program to use.

I had assumed that OSgeo4W installed everything I would need to run shell scripts in Windows. What am I missing?

Best Answer

It turns out that I forgot to type sh before the shell script in the osgeo4w. I also had an extra pair of quotes after hillshade in script. Once I removed the quotes and typed "sh hillshade.sh" into the osgeo4w shell everything worked like a charm. See below for the updated and correct script.

for f in *.tif
do
  echo "Processing $f"
gdaldem hillshade $f $f-hillshade -z 1.0 -s 1.0 -az 315.0 -alt 45.0 -compute_edges -of GTiff
done
Related Question