Starting your first shell script

Open your favorite editor and type this:
#!/bin/sh

The #! means that the following command will be used to interpret the contents of the script. In this case, that command is /bin/sh (the Bourne shell) which makes this script a shell script. If the first line were #!/usr/bin/perl then this would be a Perl script. Each shell (such as Bourne, C, Korn, and Bash) and scripting language (such as Perl, Python, and PHP) have their own commands and syntax which are often incompatible.

On the next line of your first shell script, type:
echo Hello, world.

Save this file (perhaps as script1.sh). Next you will need to make sure you can execute it. Do this using ls and then use chmod if necessary. Now you can run it: ./script1.sh . The output should simply be the message Hello, world.



Matt Disney 2005-09-14