From owner-freebsd-stable@FreeBSD.ORG Mon Jul 20 03:17:06 2009 Return-Path: Delivered-To: stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A7C27106564A for ; Mon, 20 Jul 2009 03:17:06 +0000 (UTC) (envelope-from smithi@nimnet.asn.au) Received: from sola.nimnet.asn.au (paqi.nimnet.asn.au [220.233.188.227]) by mx1.freebsd.org (Postfix) with ESMTP id C5A148FC0A for ; Mon, 20 Jul 2009 03:17:05 +0000 (UTC) (envelope-from smithi@nimnet.asn.au) Received: from localhost (localhost [127.0.0.1]) by sola.nimnet.asn.au (8.14.2/8.14.2) with ESMTP id n6K2uUDr094538; Mon, 20 Jul 2009 12:56:30 +1000 (EST) (envelope-from smithi@nimnet.asn.au) Date: Mon, 20 Jul 2009 12:56:29 +1000 (EST) From: Ian Smith To: Mark Andrews In-Reply-To: <200907200102.n6K12h1Y048534@drugs.dv.isc.org> Message-ID: <20090720120342.H6107@sola.nimnet.asn.au> References: <4ad871310907191717g1ed90be7y92250f2addc38d43@mail.gmail.com> <200907200102.n6K12h1Y048534@drugs.dv.isc.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Cc: stable@freebsd.org, Glen Barber Subject: Re: Shell execution ( [was] Re: Value of $? lost in the beginning of a function.) X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Jul 2009 03:17:06 -0000 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