Shell programming style -- a plea for better shell scripts

gwyn%brl-vld at sri-unix.UUCP gwyn%brl-vld at sri-unix.UUCP
Sun Feb 26 10:38:37 AEST 1984


From:      Doug Gwyn (VLD/VMB) <gwyn at brl-vld>

You missed the point.

#!/bin/sh

will be treated as a comment by the Bourne shell, so its presence
cannot possibly hurt.  Further, if this is NOT the first line in a
Bourne shell script that is invoked by a Cshell user, the Cshell
will attempt to interpret the commands, which usually results in a
portion of the contents of the script actually being executed before
it bombs.  By having the funny first line in your Bourne shell
scripts, even if a Cshell user runs one of them it will be executed
correctly since the Berkeley kernel will exec /bin/sh to handle it.

It is better to set the $PATH than to define explicit path names
for standard UNIX system commands.  For example, is "sort" in /bin
in your system?  It's in /usr/bin in others, except I want the one
in /usr/5bin which has all the bugs fixed.  When the /usr/5bin/sort
is moved into /usr/bin I do not want to have to track down all the
shell scripts and change "SORT=/usr/5bin/sort" to "SORT=/usr/bin/sort".
By setting PATH=/usr/5bin:/bin:/usr/bin I have GUARANTEED getting the
standard UNIX System V "sort" command regardless of where it actually
lives, which is in different places on our different UNIX systems.

An "Elements of Shell Programming Style" may be a good idea (in fact
there are good guides already available in Bourne's and Kernighan &
Pike's books), but you're not the one to write it..



More information about the Comp.unix mailing list