Unix Support

Simple Shell Scripting for Scientists

If you wish to attend this course, please ensure that you satisfy its prerequisites. (No previous experience of shell scripting is required for this course, however some knowledge of the interactive use of the Bourne-Again SHell (bash) is required; see the prerequisites for details.)

Course description

This course is part of the Scientific Computing series, and as such the examples chosen are of most relevance to scientific computing.

This course introduces shell scripting in the Bourne-Again SHell (bash) for scientific computing tasks. Day one introduces very basic shell scripts in bash which process the command line in a simple fashion. Day two covers how to write more advanced shell scripts in bash. Day three covers how to make one's shell scripts more robust.

At the end of each day of the course one or more exercises are set. It is VERY IMPORTANT that attendees attempt these exercises before the next day of the course. Attendees should make sure that they have allowed themselves sufficient study time for these exercises between each day of the course.

Upon completion of this course, attendees may find it useful to look at the course notes for the “Unix Systems: Further Commands” course, as these notes introduce more sophisticated Unix commands that could be used in shell scripts.

The course notes are available here.

Day one:

  • Recap of common Unix/Linux commands
  • What is a shell script and how does it work?
  • Errors in shell scripts
  • Writing very simple shell scripts
  • Comments in shell scripts
  • Simple use of shell builtin commands: cd, echo, export, pwd, set
  • Simple use of shell variables and parameters
  • Simple processing of the command line
  • Redirecting standard output
  • Shell flow of control constructs: for
  • Translating your task into a shell script
  • Writing more useful shell scripts

Day two:

  • Solution to exercise from previous day
  • Structuring shell scripts
  • Testing and debugging shell scripts
  • Simple use of shell builtin commands: pwd, read, test
  • Shell flow of control constructs: while
  • Shell functions
  • Command substitution
  • The mktemp command
  • Obtaining input from the keyboard/standard input
  • Pipelines
  • Arithmetic expansion
  • Translating your task into a shell script
  • Writing more advanced shell scripts

Day three:

  • Solution to exercises from previous day
  • Handling errors in shell scripts
  • Simple use of shell builtin commands: exit, return, set, source, test
  • Shell flow of control constructs: if
  • Redirecting standard error
  • Handling filenames
  • More advanced use of shell variables (parameter expansion)
  • Structuring shell scripts
  • Translating your task into a shell script
  • Writing more advanced shell scripts
  • Briefly covered in course notes: case shell flow of control construct
  • Briefly covered in course notes: more advanced processing of the command line

Notes

In due course the notes for this course will be made available in their original format. In the meantime they are available here as PDFs.

Day one: Notes (PDF) Exercise and this day's course files
Day two: Notes (PDF) Exercises and this day's course files
Day three: Notes (PDF) Exercise and this day's course files

The course notes featured an appendix with a list of useful Unix/Linux commands. This is available (currently only as a PDF) here.

All comments or questions regarding this course, and any course materials provided, should be sent to scientific-computing@ucs.cam.ac.uk.

The title of this document is: Simple Shell Scripting for Scientists
URL: http://www-uxsup.csx.cam.ac.uk/courses/moved.ShellScriptingSci/index.html