I'd like to work through the MODIS-Aqua example here.

But typically the hardest bit is getting off the ground. What specifically does it mean by 'shell scripting'? is it referring to the command console? Python console?

To get started I tried the 'Decompress' example bzip2 -d A20023532002360.L3m_8D_SST_4.bz2 in both command and python consoles - neither worked - I expect I need to get the file path in there, but not sure of the syntax. The file currently resides in the Project>Mapset folder where I thought the default path would lead - is that the best place for it?

The next big hurdle will be creating the loop to process hundreds of hdf files, but i can't get off the mark until I work out some of the very basics. Sorry, this is my first foray into GRASS scripting. Any help would be most appreciated!


2 Answers 2


You should mention which operating system you're working on. "Shell scripting" refers to a UNIX/Linux shell. If you're on windows, you may find that moving over to python programming will be you're best option.

As to the "Project>Mapset" folder, you don't need to put the *.bz2 file there. Go to the download folder (where you originally downloaded the MODIS file), unzip the file in that folder, and do the gdal_translate steps there.

Now start GRASS (from the same folder) and run the r.in.gdal step. THis imports the Geotiff raster created by gdal_translate into GRASS as a GRASS raster automatically placing everything in the Mapset folder. Now, within GRASS you do the rest of the process.


As mentioned above, it would be useful to include information on your system (OS, version of GRASS etc) as the implementation of scripts will differ slightly. Simply put, a shell script is a plain text file with a series of commands that are interpreted by the operating system's shell. If you are running GRASS on Linux or Mac, you will be able to use the Bash shell.

If you want to import multiple raster images into your GRASS. You should first create a GRASS Location. Then in the directory where you downloaded the MODIS files, you should unzip them. If you have a Bash shell then:

for `file in ls *.b2z`
   bunzip2 $file

You will then need to import the files into your GRASS Mapset. You can either use the GUI to import multiple images and navigate to the directory where your unzipped images are:

enter image description here

Or you can run another for loop in the shell as follows, which is also described on the GRASS 6 Tutorial page (n.b. you should either be in the directory where your unzipped images are or else you will need to specify the relative pathname to the files)

for image in `ls *.hdf`
   #the {image%.hdf} strips the file extension
   r.in.gdal input=$image output=${image%.hdf}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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