Simple Shell Scripting for Scientists, Day Three: Exercise

This is an exercise for you to try once you have attended the third day of the Simple Shell Scripting for Scientists course.

The course notes for this day of the course are available (as a PDF) here.

This exercise was designed to be done on PWF Linux. It is recommended that you try it on a PWF Linux system, as that is the environment in which it has been tested. However, it should work on most modern Linux distributions that have Python 2.4, 2.5, 2.6 or 2.7, gnuplot 4.0 or higher (with PNG support), and Eye of GNOME 2.9.0 or higher (or another appropriate PNG viewer), installed.

If you don't do this exercise under PWF Linux you may need to recompile the iterator program (see the README file in the archive of files from the third day of this course for details) if you want to try out the scripts used during the course. You should also have a look at the compatibility notes.

Obtaining the files for this exercise

In order to do this exercise, you'll need to get hold of the files used in class. If you are doing this on PWF Linux, then after you have logged in, type the following:

You'll be asked for a directory into which the files should be placed, the files will be unpacked to that directory and then set up for you. Look at the README file in the directory to which the files have been unpacked for instructions on how to run the script constructed in class.

If you are not doing this exercise on PWF Linux, then you'll need to get copies of the files that were used in class onto your own system and set up properly. These files are available in an archive here. You'll also need to unpack the archive and set things up with this setup-day-three.sh script. Download the archive and setup-day-three.sh script to the same directory. cd to the directory into which you downloaded those two files. Make sure the setup-day-three.sh script is executable by typing:

and then run it by typing:

The setup-day-three.sh script will ask you for a directory into which it should unpack the archive and will then set everything up for you.

Once the archive is successfully unpacked, see the README file for details of what it contains. This file also gives brief instructions on how to recompile the iterator source code, in case the precompiled version of iterator included in the archive won't run on your system.

Simple Shell Scripting for Scientists, Day Three: Final exercise

The point of this exercise is to consolidate everything you've learnt over all three days of this course. To that end you should write your own shell script FROM SCRATCH for this exercise - do not just take one of the ones constructed in this course and change the names of the programs it runs. Whilst you could certainly get an answer to this exercise that way, you wouldn't learn very much.

You should make your shell script as good a shell script as you can possibly make it. Even if you never bother to be this meticulous ever again when writing your own shell scripts, your understanding of shell scripting will be greatly improved if your answer to this exercise is a carefully thought out, robust shell script that follows the guidelines you have met in this course.

In other words, the shell script you write in answer to this exercise should:

…and so on.

In the archive you will find a program called lissajous.py which produces points on a Lissajous curve that it prints to standard output. lissajous.py takes two floating point command line arguments, although in this exercise we'll restrict ourselves to using only integer arguments for it.

In the gnuplot subdirectory there is a file of gnuplot commands called lissajous.gplt that can be used to plot the data produced by lissajous.py. The commands in this file expect their input to be in a file called lissajous.dat in the current directory, and they produce a PNG file called lissajous.png (also in the current directory).

Write a shell script that will read the first parameter for lissajous.py from standard input and the second parameter from the command line. It should run the lissajous.py program, turning its output into a graph using gnuplot.

Here's an example that illustrates how your shell script should combine the arguments it reads from standard input with the ones it obtains from the command line:

There is a file in the scripts subdirectory called lissajous_params that you can use as a source of parameters to read via standard input. For the command line arguments you can use:

 

Compatibility notes

If you are not doing this exercise under PWF Linux then you should be aware of the following issues which may arise when using other Linux/Unix systems: