From owner-freebsd-stable@FreeBSD.ORG Mon Jul 20 01:02:49 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 3ABA31065674 for ; Mon, 20 Jul 2009 01:02:49 +0000 (UTC) (envelope-from marka@isc.org) Received: from farside.isc.org (farside.isc.org [IPv6:2001:4f8:3:bb::5]) by mx1.freebsd.org (Postfix) with ESMTP id 1FC5D8FC17 for ; Mon, 20 Jul 2009 01:02:49 +0000 (UTC) (envelope-from marka@isc.org) Received: from drugs.dv.isc.org (drugs.dv.isc.org [IPv6:2001:470:1f00:820:214:22ff:fed9:fbdc]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "drugs.dv.isc.org", Issuer "ISC CA" (not verified)) by farside.isc.org (Postfix) with ESMTP id 75A66E606E; Mon, 20 Jul 2009 01:02:48 +0000 (UTC) (envelope-from marka@isc.org) Received: from drugs.dv.isc.org (localhost [127.0.0.1]) by drugs.dv.isc.org (8.14.3/8.14.3) with ESMTP id n6K12h1Y048534; Mon, 20 Jul 2009 11:02:45 +1000 (EST) (envelope-from marka@drugs.dv.isc.org) Message-Id: <200907200102.n6K12h1Y048534@drugs.dv.isc.org> To: Glen Barber From: Mark Andrews References: <4ad871310907191717g1ed90be7y92250f2addc38d43@mail.gmail.com> In-reply-to: Your message of "Sun, 19 Jul 2009 20:17:22 -0400." <4ad871310907191717g1ed90be7y92250f2addc38d43@mail.gmail.com> Date: Mon, 20 Jul 2009 11:02:43 +1000 Sender: marka@isc.org Cc: stable@freebsd.org 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 01:02:50 -0000 In message <4ad871310907191717g1ed90be7y92250f2addc38d43@mail.gmail.com>, Glen Barber writes: > Possibly off-topic... > > > 2009/7/19 Glen Barber : > > 2009/7/19 Romain Tarti=E8re : > >> Hi Glen, > >> > >> On Sun, Jul 19, 2009 at 04:32:28PM -0400, Glen Barber wrote: > >>> > % sh foo.sh > >>> > % zsh foo.sh > >>> > % bash foo.sh > >>> What happens if you replace '#!/bin/sh' with '#!/usr/local/bin/zsh' ? > >> > >> This is not related to my problem since I am not running the script > >> using ./foo.sh but directly using the proper shell. =A0sh just behaves > >> differently, that looks odd so I would like to know if it is a bug in sh > >> or if there is no specification for this and the behaviour depends of > >> the implementation of each shell, in which case I have to tweak the > >> script I am porting to avoid this construct (passing $? as an argument > >> for example). > >> > >> Romain > >> > > > > 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? > > --=20 > Glen Barber > _______________________________________________ > freebsd-stable@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-stable > To unsubscribe, send any mail to "freebsd-stable-unsubscribe@freebsd.org" "#!" 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. Mark -- Mark Andrews, ISC 1 Seymour St., Dundas Valley, NSW 2117, Australia PHONE: +61 2 9871 4742 INTERNET: marka@isc.org