Chapter 10. Additional Information

Table of Contents

The shell environmental variables pertaining to scripting
The Source command
the exec command
Other methods of executing a script or a series of commands

The shell environmental variables pertaining to scripting

We're going to have a brief look at the shell and the environment variables that are set by the shell.

We talked a little earlier about the difference between shell and environment variables, where shell variables are not exported as opposed to environment variables, which are.

We talked about starting subshells; shells having subshells (children). When we exit a subshell we return to a parent shell.

To show a list of environment variables, type:


To show a list of shell variables, type:


The bash prompt is represented by the shell variable called PS1.


echo $PS1

which displays the following on my system:

\e[31;1m\[[\u@\h \[\e[32;1m\]\w\[\e[31;0m\]]$\[\e[0;0m\]
[Note] Note

if your prompt does not show exactly the same thing as shown here, don't worry. You can set the prompt to anything you like. I just like a colourful one!

man bash

and search for the word PROMPTING as follows:


you will find all the settings your PS1 variable can assume.

The PS2 variable is a prompt too, and this is used when you have a run-on line. Try:

echo "Hello


This is waiting for you to close the double quotes to finish the command.

echo "Hello

> World"

Hello World

Then back to your prompt.

Another example:

ls \


Here list is still waiting for you to complete the command, and your new line will then display the PS2 prompt. Now type -sl, so that it looks like:

ls \

The \ (the line break) allows us to split lines over more than a single line.

These variables (PS1, PS2, etc.) are shell variables, so using the env command will not show them.

set, on the other hand will.

Environmentals variables such as HOME (your home directory), USER (your username), LOGNAME (your login name), MAIL (your mail directory) are set at shell startup time.

Additionally, you have special environment variables such as:

~ and	~-

Tilde (~) is your home directory (in my case /home/hamish), so:

cd ~

will take you back to your home directory, irrespective of where you currently are on the system.

The ~- will return you to the previous directory you were working in, this would be held by OLDPWD, as set in the environment.

cd ~-