Which shell language should I use?
Chuck Karish
karish at forel.stanford.edu
Sat Apr 29 18:59:15 AEST 1989
In article <113700004 at uxa.cso.uiuc.edu> gsg0384 at uxa.cso.uiuc.edu wrote:
>1. How much of the Berkeley-originated script files were written
>in Bourn-shell language?
A good exercise for the original poster. Write a script
to look for csh syntax/magic cookies in all the scripts
on your machine. I'd use `find', `file', and `sed' to
do it.
> It seems to me that such practice enhances
>portability. I'd like to hear some opinion on which shell-sript
>language is preferable for what purpose.
I agree. csh is not present on all systems, and differs
from implementation to implementation, mostly because
a few vendors ship ancient versions.
The most portable scripts use the subset of the modern
sh language that's supported by the V7/BSD sh program.
sh is a better language than csh for writing complex
programs. Its quoting syntax is less idiosyncratic,
and its flow-of-control operators work with pipes
and redirection. In sh, it's possible to redirect the
output of a `while' loop. In csh, you'd have to create
a subshell yourself. Similarly, sh lets you redirect
different output streams of the same command to different
files; under csh, you'd have to use another subshell.
>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 ...
Some systems read the first line, and use this as the
name of the interpretor to use. Some just recognize
the '#' as the first character in the file as a signal
to use csh.
The default is to use sh, if no magic cookie at all
is found.
Does not work at all unless the script is invoked from
execlp() or execvp().
>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?
execl(3), execve(2)
Chuck Karish {decwrl,hpda}!mindcrf!karish
(415) 493-7277 karish at forel.stanford.edu
More information about the Comp.unix.questions
mailing list