Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 20 Jul 2009 12:56:29 +1000 (EST)
From:      Ian Smith <smithi@nimnet.asn.au>
To:        Mark Andrews <marka@isc.org>
Cc:        stable@freebsd.org, Glen Barber <glen.j.barber@gmail.com>
Subject:   Re: Shell execution ( [was] Re: Value of $? lost in the beginning of a function.) 
Message-ID:  <20090720120342.H6107@sola.nimnet.asn.au>
In-Reply-To: <200907200102.n6K12h1Y048534@drugs.dv.isc.org>
References:  <4ad871310907191717g1ed90be7y92250f2addc38d43@mail.gmail.com>  <200907200102.n6K12h1Y048534@drugs.dv.isc.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 20 Jul 2009, Mark Andrews wrote:
 > In message <4ad871310907191717g1ed90be7y92250f2addc38d43@mail.gmail.com>, Glen 
 > Barber writes:
 > > Possibly off-topic...
[..]
 > > > My understanding was this:
 > > >
 > > > If you specify 'sh foo.sh' at the shell, the script will be run in a
 > > > /bin/sh shell, _unless_ you override the shell _in_ the script.
 > > >
 > > > Ie, 'sh foo.sh' containing '#!/bin/sh' being redundant, but 'zsh
 > > > foo.sh' containing '#!/bin/sh' would execute using zsh.
 > > >
 > > >
 > > 
 > > I meant to say in the last line: "'#!/bin/sh' would override the 'zsh' shel=
 > > l."
 > > 
 > > Can someone enlighten me if I am wrong about this?
 >
 > "#!" is used to define the interpretor when the file is exec'd.
 > 
 > perl, AFAIK, is the only interpretor that will look at what is after
 > the "#!" and modify it's behaviour.  All other a interpretors (shells)
 > treat "#!" as a comment.
 > 
 > Some shells used to examine the executable about to be called and
 > looked for "#!" and invoke the correct interpretor.  This was how
 > "#!" was supported before kernels has support for "#!".  It was all
 > done in userland.

Some rexx scripts begin with this cute trick so they may be executed in 
any (UNIXish) shell as 'program', or specifically as 'rexx program', 
where it's just a regular rexx comment:

/*usr/bin/true;exec rexx -x "$0" "$@";exit# ReXX */
  /* Take a measure of REXX clauses-per-second (CPS)                 */
  /* Mike Cowlishaw (mfc@ibm.com).  Multi-platform.                  */
  /* 1.0 17 Jan 89 Original version                                  */

though I never understood why an exit would be needed after an exec .. 
just making sure I guess, or maybe catering for some variant or other.

cheers, Ian



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090720120342.H6107>