Introduction to Borne Shell Scripts

Borne shell scripts are wonderful things. You just fill your script up with all of the Borne commands you want and then execute it. Shell scripts are very comparable to Window's BATCH file. The scripts themselves are ASCII text files, and not binary.

The begining of your shell script should be something like:

#! /bin/sh

When executed, this tells the computer that this is a Borne script. With that declaration as the only exception, all other lines beginning with a pound sign (#) are comments, and will have no effect on the script.

The following is a valid Borne script:

#! /bin/sh

# Output 'Hello World' to the terminal
echo "Hello World"

In order to execute this, you will have to change its file permissions to allow execution. Then exectution is simply: ./file-name. The file can also be put in an directory included in your PATH variable so that you can simply call file-name from any directory.

Let's build on that first script just for practice.

#! /bin/sh

echo "Hello World!"

# Now print 'My name is _____ and my username is _____'
echo "My name is $1 and my username is $USER."

You're probably wondering where all that came from. Firstly, the '$1' refers to the first argument the script gets during execution. The dollar sign means that it is a variable. $USER is an envirornmental variable already set to your username.

Valid HTML 4.01 Transitional

Valid CSS!

(c) 2005 Nic Reveles
Updated