Path: utzoo!utgpu!watserv1!watmath!att!att!emory!samsung!cs.utexas.edu!sun-barr!apple!altos!megadon!clp From: gwc@root.co.uk (Geoff Clare) Newsgroups: comp.unix Subject: Re: Shell scripts starting with "#" Message-ID: <2236@megadon.UUCP> Date: 24 Oct 90 02:53:24 GMT References: <3695@zorba.Tynan.COM> <2136@megadon.UUCP> <2225@megadon.UUCP> <2227@megadon.UUCP> Sender: clp@megadon.UUCP Organization: UniSoft Ltd., London, England Lines: 28 Approved: clp@megadon.UUCP In <2227@megadon.UUCP> peter@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 (Dumb American mailers: ...!uunet!root.co.uk!gwc) UniSoft Limited, Hayne Street, London EC1A 9HH, England. Tel: +44-71-315-6600