On Mon, 20 Jul 2009, Mark Andrews wrote:
 > In message <4ad871310907191717g1ed90be7y92250f2addc38...@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 (m...@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
_______________________________________________
freebsd-stable@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-stable
To unsubscribe, send any mail to "freebsd-stable-unsubscr...@freebsd.org"

Reply via email to