Scripts and functions

Shell scripts (9 min + 3 min)

We now know a lot of UNIX commands! Wouldn’t it be great if we could save certain commands so that we could run them later or not have to type them out again? As it turns out, this is extremely easy to do. Saving a list of commands to a file is called a “shell script”. These shell scripts can be run whenever we want, and are a great way to automate our work.

Here is a an example of processing files with scripts:

Variables (7 min)

Functions (13 min)

Functions are similar to scripts, except that we reference a function by its name. Therefore, once defined, a function can be run in any directory, whereas running a script in another directory requires its path.

A convenient place to put all your function definitions is ~/.bashrc file which is run every time you start a new shell (local or remote).