Unix Shell and other UNIX Information

Why Use Shells?

from http://www.injunea.demon.co.uk/pages/page203.htm

Well, most likely because the are a simple way to string together a bunch of UNIX commands for execution at any time without the need for prior compilation. Also because its generally fast to get a script going. Not forgetting the ease with which other scripters can read the code and understand what is happening. Lastly, they are generally completely portable across the whole UNIX world, as long as they have been written to a common standard.

The Shell History:

The basic shells come in three main language forms. These are (in order of creation) sh, csh and ksh. Be aware that there are several dialects of these script languages which tend to make them all slightly platform specific. Where these differences are known to cause difficulties I have made special notes within the text to highlight this fact. The different dialects are due, in the main, to the different UNIX flavours in use on some platforms. All script languages though have at their heart a common core which if used correctly will guarantee portability.

Bourne Shell:

Historically the sh language was the first to be created and goes under the name of The Bourne Shell. It has a very compact syntax which makes it obtuse for novice users but very efficient when used by experts. It also contains some powerful constructs built in. On UNIX systems, most of the scripts used to start and configure the operating system are written in the Bourne shell. It has been around for so long that is it virtually bug free. I have adopted the Bourne shell syntax as the defacto standard within this book.

C Shell:

Next up was The C Shell (cshrc), so called because of the similar syntactical structures to the C language. The UNIX man pages contain almost twice as much information for the C Shell as the pages for the Bourne shell, leading most users to believe that it is twice as good. This is a shame because there are several compromises within the C Shell which makes using the language for serious work difficult (check the list of bugs at the end of the man pages!). True, there are so many functions available within the C Shell that if one should fail another could be found. The point is do you really want to spend your time finding all the alternative ways of doing the same thing just to keep yourself out of trouble. The real reason why the C Shell is so popular is that it is usually selected as the default login shell for most users. The features that guarantee its continued use in this arena are aliases, and history lists. There are rumours however, that C Shell is destined to be phased out, with future UNIX releases only supporting sh and ksh. Differences between csh and sh syntax will be highlighted where appropriate.

Example .cshrc

Korne Shell:

Lastly we come to The Korne Shell (ksh) made famous by IBM's AIX flavour of UNIX. The Korne shell can be thought of as a superset of the Bourne shell as it contains the whole of the Bourne shell world within its own syntax rules. The extensions over and above the Bourne shell exceed even the level of functionality available within the C Shell (but without any of the compromises!), making it the obvious language of choice for real scripters. However, because not all platforms are yet supporting the Korne shell it is not fully portable as a scripting language at the time of writing. This may change however by the time this book is published. Korne Shell does contain aliases and history lists aplenty but C Shell users are often put off by its dissimilar syntax. Persevere, it will pay off eventually. Any sh syntax element will work in the ksh without change.

Read That Manual!

On any UNIX system the on-line documentation available from the man pages covers all the commands available, including the script languages. For Bourne it's usually between 10 and 15 pages whereas for C Shell or Korne it's about 30 pages or more. It is a good idea to get this printed out and put into a loose leaf folder. The on-line documentation is always more up to date than that in the printed manuals that arrive with the system and if stored in normal A4 folders (I use the clear plastic pockets to store the loose pages) this can be used as your reference source. People usually gasp in horror when they hear this - "Why not just open a new window and use man!" - they cry. Well for one thing, if I know the information I want is towards the back, I can jump straight to the page rather than fight with the scrollbar. Secondly, if the information is wrong (Heaven Forbid!) or not too clear (Really?), I can add some of my own clarification in the margins! The all important dialect or platform specifics will also be listed within these man pages.


Shortcuts to Code Examples and Zipped Word Docs


Home Page Previous Next


(TOP)
Intranet Website -
For information or questions regarding this web page, please contact Steve Salkow