home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!uknet!acorn!ixi!ixi!pd
- From: pd@x.co.uk (Paul Davey)
- Newsgroups: comp.unix.questions
- Subject: Re: ':' line in scripts [LONGish]
- Message-ID: <PD.92Sep14184828@herts.x.co.uk>
- Date: 14 Sep 92 18:48:28 GMT
- References: <1992Sep11.163325.7096@qcinet.Gwinnett.COM>
- Sender: paul@x.co.uk (Paul Davey)
- Organization: IXI Ltd.
- Lines: 85
- In-Reply-To: dpayton@qcinet.Gwinnett.COM's message of 11 Sep 92 16:33:25 GMT
-
- >>>>> On 11 Sep 92 16:33:25 GMT, dpayton@qcinet.Gwinnett.COM (Doug Payton) said:
-
- Doug> I've seen, on occasion, scripts that begin with the line
-
- Doug> :
-
- Doug> which, as I recall, is simply 'true'. Sometimes I've seen
-
- Doug> #!/bin/sh
- Doug> :
-
- Doug> ...but the ':' is still there.
-
- Doug> What is it's purpose? Does it init the shell to a known state?
-
-
- From sh(1)
-
- : No effect; the command does nothing. A zero exit code is returned.
-
-
- Once upon a time, many releases ago, (when the epoch was a recent event)
- Unix machines introduced the idea of exectable text files.
-
- This was possible on other operating systems of the time, but Unix
- allowed not just a command such as ``sh foo'' but ``foo'' when foo
- was a file containing text, but was not a binary exectable.
-
- Early shells had no comment character but the ``:'' could be used to
- almost do this. (One had to be wary of redirections and substitutions
- which would be still be carried out in ``comment'' lines such as -
-
- : This is my new program , try it with foo > filename
- ... (script)
-
- or more usefully
-
- : This exits if this variable substitution fails ${user?}
-
- Then those useful people at UCB wrote a new shell, with an
- (alleged) syntax similar to C.
-
- The C shell (as it was imaginatively called) introduced a wealth of
- good things* including a comment character ``#''. Scripts starting
- with this character could therefore be executed by csh.
-
- [* see footnote]
-
- Scripts were passed to the Bourne shell if some other character was
- seen first and so ``:'' was often used. This behaviour survives (on
- BSD based machines) even to this day when the Bourne shell recognises
- ``#'' as a comment itself.
-
- Systems differ as to whether an initial ``#'' signifies a (default)
- Bourne shell or a C shell script. This means that Bourne shell scripts
- called from an interactive C shell may be run erroneously by the C
- shell.
-
- Note: It is possible to override the meaning of a single initial
- ``#'' in the C shell by saying:
-
- ``set shell = /bin/sh''
-
- This is *not* the same as:
-
- ``setenv SHELL /bin/sh''.
-
-
- Later still some bright young sparc(?) decided to allow any command
- intrepreter to be specified as the first line of a script file.
-
- Thus the syntax for ``#!/bin/prog'' or ``#!prog'' was
- introduced, where prog could be any program able to read
- commands from the rest of the file.
-
- Amoung the other good things from UCB was a new filesystem and
- kernal the latter of which was adjusted to recognise the ``#!''
- syntax and would execute the appropriate script.
-
- Sadly certain other vendors have taken a long long time to even begin
- to introduce this handy syntax and so Bourne shell scripts are
- sometimes still written with a first line of ``:'' to ensure that they
- are executed by the Bourne shell.
-
- Footnote: Readers who wish to mention ksh, bash or zsh
- here are firmly directed to /dev/null.
-
-
- --
- Regards, pd@x.co.uk IXI Ltd.
- Paul Davey pd@ixi.uucp 62-74 Burleigh St.
- ...!uunet!ixi!pd Cambridge, U.K.
- "These _are_ interesting times" +44 223 462 131 CB1 1OJ
-