Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
  echo "Processing $f"
gdaldem hillshade $f $f-hillshade" -z 1.0 -s 1.0 -az 315.0 -alt 45.0 -compute_edges -of GTiff

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?

share|improve this question

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" into the osgeo4w shell everything worked like a charm. See below for the updated and correct script. Man this is going to save me a ton of time!

for f in *.tif
  echo "Processing $f"
gdaldem hillshade $f $f-hillshade -z 1.0 -s 1.0 -az 315.0 -alt 45.0 -compute_edges -of GTiff
share|improve this answer
If this answers your question, please mark it as accepted (click grey checkmark below question vote count up/down). – Chad Cooper Dec 31 '12 at 0:58
sh files are used in the linux world. The Windows command line equivalent are .bat files. These do not need a sh command to start them. – AndreJ Jan 27 '15 at 16:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.