next up previous contents
Next: Variables Up: Shell Programming Previous: Shell Scripts   Contents

Running and Debugging

There are several ways to run scripts:-

As a child process with a default shell
For example:-

./my_commands
This executes the my_commands file as a child process with the shell as specified on the first line (if the #! trick is used) or the default shell if not.

As a child process with a explicit shell
For example:-

sh -x my_commands
This executes the my_commands file as a child process with the Bourne shell. The -x is optional and results in each line being typed out as it is executed which helps when debugging.

To do the same thing in the C shell:-

csh -x my_commands

Within the parent shell
This is called ``sourcing'' and in effect acts as if the commands had been typed directly at the terminal. To do the for the bash shell:-
. my_commands
(yes the command really is just a dot!) and for the c shell:-
source my_commands

The most common reason to source a script like this rather than run it as a separate child process is because it contains commands that change your environmental variables (see section 6.2.5). If you were to execute these in a child process they would only change its environment and would be lost when the child process terminated.

You can only source script files that are suitable for the parent shell.
So if you use the C or T shell as your interactive shell then you will have to write any script you want to source using the C shell.


next up previous contents
Next: Variables Up: Shell Programming Previous: Shell Scripts   Contents
P.D. Gronbech (IT Staff) 2015-10-02