Shell scripts starting with "#"
Geoff Clare
gwc at root.co.uk
Wed Oct 24 12:53:24 AEST 1990
In <2227 at megadon.UUCP> peter at ficc.ferranti.com (Peter da Silva) writes:
>So if you do:
> #!/bin/sh
> : || exec /bin/sh $0 $argv:q
> (alias) >/dev/null 2>&1 && exec /bin/sh $0 "$@"
>
>It'll work for the bourne shell, the korn shell, and the c shell, whether
>or not you have #! working. Geeze.
But only if your script treats a single null argument the same as no
arguments, and doesn't have any special characters in it's name.
If you want to be that little bit more robust, replace Peter's
$0 "$@"
with
"$0" ${1+"$@"}
It's probably also worth pointing out that mechanisms of this type
rely on the process which executes the script being well behaved.
If executed from a program which does an
execl("/somewhere/your_script", "ha ha, gotcha!", (char *)0);
or from a shell whose local search path is different to the value of
PATH it exports, then all bets are off.
--
Geoff Clare <gwc at root.co.uk> (Dumb American mailers: ...!uunet!root.co.uk!gwc)
UniSoft Limited, Hayne Street, London EC1A 9HH, England. Tel: +44-71-315-6600
More information about the Comp.unix
mailing list