Which shell language should I use?
Phil Hughes
fyl at ssc.UUCP
Tue May 2 06:34:26 AEST 1989
In article <113700004 at uxa.cso.uiuc.edu>, gsg0384 at uxa.cso.uiuc.edu writes:
> I simply thought that I should use the C-shell script language since
> I am using /bin/csh as an interactive shell. But
> I found, and was surprised, that most shell script files are Bourn-shell
> script files. Even some of the Berkely-originated source were
> wriiten in Bourn-shell language.
The cute answer is "use Bourne shell" so you can buy our tutorial on it.
:-) But, there is more.
Generally, scripts are written using Bourne shell because it is portable
(available on all UNIX systems) and generally executes faster. There is
the short answer. Now, here is what we have done at SSC.
Almost all of our shell scripts are written using the Bourne shell.
The exceptions are scripts where having arrays available within the shell
made the job much less complicated. On the other hand, almost all of out
users use csh interactively.
I teach two different classes where the students do shell work. In the
more general one (called UNIX for Programmers but it is just UNIX for
technically oriented people) I teach shell programming using csh. I made
this decision because I felt it was easier to explain some concepts using
csh. For example, the relationship between the shell and the environment
and dealing with arithmetic on strings. The other class, which is a 1-day
seminar on writing (as much as I hate to use this word) business
applications using UNIX tools is taught using Bourne shell. The
difference is that in UFP I am showing concepts and at the end of the
sction on csh I do a comparison between the shells. In the applications
class I am really teaching the use of the utilities and how to use the
shell as "glue". I expect people to take the examples from this class and
apply them directly to solve a problem.
In other words, here are some ideas but you need to take your pick.
> 1. How much of the Berkeley-originated script files were written
> in Bourn-shell language?
My guess -- most.
> 2. I found that the first line of a shell-script file is special
> even though it contains '#'. Sometimes I found, and sometimes not,
>
> #!/bin/csh
>
> or
>
> #!/bin/sh
>
> in the first line. They looks like directives. Am I right?
Yes. Not all shells understand these (XENIX being the biggest example).
But, if your shell is smart enough to undersand it is a directive to the
shell that /bin/csh or /bin/sh is the correct program to interpret what
follows. Note that this could be the name of any program, not just the
Bourne or C shell.
> 3. Where in the UNIX manual can I find some kind of rule on which
> shell-script parser is applied for a certain shell-script file?
Your SHELL environment variable determines which shell is invoked to
interpret a script. If this is csh and the first character of the script
is not a #, csh passes the script to the Bourne shell.
> 4. Please recommend a book on shell programming.
UNIX Shell Programming by Kochan and Wood is fairly comprehensive.
For C shell, The C Shell Field Guide by Anderson and Anderson is
excellent. And, for a pocket guide to the Bourne shell, we (SSC)
publishes the Bourne Shell Pocket Tutorial.
Good luck.
--
Phil Hughes, SSC, Inc. P.O. Box 55549, Seattle, WA 98155 (206)FOR-UNIX
uw-beaver!tikal!ssc!fyl or uunet!pilchuck!ssc!fyl or attmail!ssc!fyl
More information about the Comp.unix.questions
mailing list