skip to content
 

Simple Shell Scripting for Scientists: Prerequisites

The following are the prerequisites for the Simple Shell Scripting for Scientists course. If you do not meet these prerequisites then you are likely to find it extremely difficult to follow this course, and we recommend that you do not attend the course until you do satisfy these prerequisites.

You can obtain the necessary knowledge to satisfy all of these prerequisites by attending the Unix: Introduction to the Command Line Interface course. However, if you attend the Unix: Introduction to the Command Line Interface course in order to meet these prerequisites, it is important that you PRACTICE what you have learnt BEFORE attending this course. This is because this course assumes not only that you have the relevant knowledge and skills, but also that you are actively familiar with them.

The Unix: Introduction to the Command Line Interface course doesn't cover every single one of the listed options for the various commands given below. If you have gone on this course to meet the prerequisites, or if you are unfamiliar with Linux systems, you should experiment with all the commands listed below (and, where given, the various options listed for that command) on a MCS Linux system before attending this course.

Prerequisites

  • Familiarity with the Unix/Linux command line and running simple commands

  • Familiarity with running commands with options (e.g. ls ‑l) and combining several command-line options (e.g. ls ‑lR)

  • Familiarity with the concept of Unix file permissions

  • Familiarity with using file name globs/wildcards (e.g. *?) to specify file names (this is sometimes called file name globbingfilename expansion or pathname expansion)

  • Familiarity with piping the output of one command into another (e.g. ls | more)

  • Familiarity with redirecting a command's input (e.g. more < filename) and output (e.g. ls > filename)

  • Familiarity with running commands in the background (e.g. ls > filename &)

  • Familiarity with the concept of environment variables and with the simple use of environment variables (e.g. setting the PATH environment variable; using the export command under the bash shell).

  • Familiarity with the following Unix/Linux commands and their most common options:
    (Note: the options listed below are for the versions of these commands provided by the Bourne-Again SHell (bash), or, where a command is not provided by the bash shell, for the GNU version of that command. The GNU versions of the commands below are the versions which are the normally found on Linux systems. Other versions of these commands (notably those supplied with Solaris) may not support all these options, or may behave differently.)

cat

Display the contents of a file.

cd

Change the current directory.

chmod

Change file or directory permissions.

cp

Copies files and directories. Useful options (some of which are used in this course) include:

-f or  ‑‑force

If unable to open destination file for writing, remove it and try again, i.e. forcibly overwrite destination files

-i or  ‑‑interactive

Prompt before overwriting anything

-p

Preserve mode, ownership and timestamp attributes of copied files (where possible)

-r or  ‑R or  ‑‑recursive

Copy directories (if any) recursively, i.e. copy their contents

-v or  ‑‑verbose

Show what is being done

date

Display or set the system date and time.

echo

Display text. Useful options (some of which are used in this course):

-e

Enable interpretation of some special character sequences (backslash escapes), such as \t (display a tab character) and \n (output a newline character, i.e. advance to the next line).

-n

Do not output a trailing newline. echo normally outputs a newline character, i.e. advances to the next line, after the text it has been told to display. This options stops it from doing that.

env

With no arguments, print the current set of environment variables.

export

Put a variable in the shell's environment, optionally setting it at the same time. This command only exists under certain Unix/Linux shells, most notably the bash shell.

less

Display a file one screenful of text at a time.

grep

Find lines in a file that match a given pattern. The pattern is specified as a regular expression.

ls

List the contents of a directory. Useful options (some of which are used in this course) include:

-1

List one entry per line

-a or  ‑‑all

Show directory entries starting with .

-A or  ‑‑almost‑all

Show directory entries starting with . except for the implied . and .. entries

-d

List directory name instead of its contents and do not follow symbolic links

-l

Use a long listing format that shows lots of information about each directory entry

-R or  ‑‑recursive

List subdirectories recursively, i.e. display their contents and the contents of any subdirectories within them, etc

mkdir

Make directories. Option(s) used in this course:

-p or  ‑‑parents

Make parent directories if neccessary. Also, if the directory to be created already exists, do not regard this as an error.

more

Display a file one screenful of text at a time. On some Linux distributions the more command is simply an alias of the less command.

mv

Moves or renames files and directories. Note that if you move a file or directory from one filesystem to another, then mv will actually copy the file or directory and then delete the original. Useful options include:

-f or  ‑‑force

Do not prompt before overwriting destination files or directories

-i or  ‑‑interactive

Prompt before overwriting destination files or directories

-v or  ‑‑verbose

Show what is being done

pwd

Print the path of the current working directory. Option(s) used in this course:

-P

Make sure the path printed does not contain any symbolic links

rm

Deletes files or directories. Useful options (some of which are used in this course) include:

-f or  ‑‑force

Ignore non-existent files and do not prompt before removing files or directories

-i or  ‑‑interactive

Prompt before removing files or directories

‑‑preserve‑root

Do not operate recursively on /

-r or  ‑R or  ‑‑recursive

Remove subdirectories (if any) recursively, i.e. remove subdirectories and their contents

-v or  ‑‑verbose

Show what is being done

rmdir

Remove empty directories.

touch

Change the timestamp of a file. If the file does not exist, create it with the specified timestamp (the default timestamp is the current date and time).

wc

Count the number of characters, words and lines in a file. Option(s) used in this course:

-l or  ‑‑lines

Print the number of lines in the file (strictly speaking, print the number of newline characters in the file).

Useful background knowledge

The following are not prerequisites, as they are either explained during the course, or else are somewhat peripheral to it. However, those attending the course will find it helpful if they are already familiar with:

  • The Bourne-Again SHell (bash), version 2.05 or higher

  • The concepts of standard inputstandard output and standard error

  • The concept of a program's exit status (also called its exit codereturn codereturn statuserror codeerror statuserrorlevel or error level)

  • The concept of a symbolic link (also known as a symlink or soft link) and the ln command (which, when used with the  ‑s option, creates symbolic links)

  • The mktemp command, which is used to safely make a temporary file or directory