First Shell Script

1: #!/bin/sh
2: PS4="\#> "
3: set -x
4: gcc -Wall -o hello2 hello2.c
5: ./hello2 ece449
6: exit

Create the above script file in a text editor with the name first.

The first line is a “magic” code that identifies the file as a shell script and identifies the shell to be used to run the script.

The last line ensures that the script returns a sensible exit code. Exit codes are rarely checked when scripts are run interactively, as we will be doing, but may be checked when invoked by other scripts.

Making A Script Executable

You can invoke a script in two ways


Maintained by John Loomis, last updated 2 February 2010