skip to content
 

Course notes

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: Introduction to the Command Line Interface”  and “Further use of Unix” courses, as these notes introduce more sophisticated Unix commands that could be used in shell scripts.

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: cdechoexportpwdset
  • 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: pwdreadtest
  • 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: exitreturnsettest
  • Shell flow of control constructs: if
  • Redirecting standard error
  • Handling filenames
  • Structuring shell scripts
  • Translating your task into a shell script
  • Writing more advanced shell scripts

Day four:

Day four is no-longer taught.  The course material is available for self-study, and covers:

  • Solution to exercise from previous day
  • Simple use of shell builtin commands: localsource
  • Lists of commands: ;&&||
  • Shell flow of control constructs: case
  • Handling filenames
  • More advanced use of shell variables (parameter expansion)
  • More advanced use of tests in if statements
  • More advanced processing of the command line
  • Translating your task into a shell script
  • Writing more advanced shell scripts

Notes

Printed copies of the course notes will be provided to those attending the course.  Electronic copies of the notes are also available:

Day one: Notes (PDF) Notes (ODT) Files (tar.gz) Instructions
Day two: Notes (PDF) Notes (ODT) Files (tar.gz) Instructions
Day three: Notes (PDF) Notes (ODT) Files (tar.gz) Instructions
Day four: Notes (PDF) Notes (ODT) Files (tar.gz) Instructions

The course notes featured an appendix with a list of useful Unix/Linux commands.

All comments or questions regarding this course, and any course materials provided, should be sent to .