UNIX Guide, for beginners and Mac OS X users
You are here: SillyDog701 > UNIX Guide >SillyDog701 > UNIX Guide > (index) supportSupport - ask in our friendly forums.

Example of a simple shell script

These are the contents of a shell script called display:

   cat display
   # This script displays the date, time, username and
   # current directory.
   echo "Date and time is:"
   date
   echo
   echo "Your username is: `whoami` \n"
   echo "Your current directory is: \c"
   pwd

The first two lines beginning with a hash (#) are comments and are not interpreted by the shell. Use comments to document your shell script; you will be surprised how easy it is to forget what your own programs do!

The backquotes (`) around the command whoami illustrate the use of command substitution.

The \n is an option of the echo command that tells the shell to add an extra carriage return at the end of the line. The \c tells the shell to stay on the same line. See the man page for details of other options.

The argument to the echo command is quoted to prevent the shell interpreting these commands as though they had been escaped with the \ (backslash) character.


[Home]UNIX Guide home | [Search]search | index
Page URL: http://sillydog.org/unix/
[SillyDog701] [Netscape] [MozInfo701] [MacCentre701] [UNIX Guide] [AntTunes701][Forums] [Search] [Change Log] [Feedback] [About Us] [Sitemap]
This UNIX Guide maintained by SillyDog701, portion of this Guide is based on UNIXhelp. UNIXhelp is copyright University of Edinburgh. This page was last modified on 14 March, 2006
Netscape NOW!Made on a Mac
support MozInfo701 and SillyDog701