From owner-freebsd-stable@FreeBSD.ORG Mon Jul 20 11:29:34 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 89652106564A for ; Mon, 20 Jul 2009 11:29:34 +0000 (UTC) (envelope-from freebsd-stable-local@be-well.ilk.org) Received: from mail8.sea5.speakeasy.net (mail8.sea5.speakeasy.net [69.17.117.10]) by mx1.freebsd.org (Postfix) with ESMTP id 5F9B58FC1E for ; Mon, 20 Jul 2009 11:29:34 +0000 (UTC) (envelope-from freebsd-stable-local@be-well.ilk.org) Received: (qmail 18472 invoked from network); 20 Jul 2009 11:02:53 -0000 Received: from dsl092-078-145.bos1.dsl.speakeasy.net (HELO be-well.ilk.org) ([66.92.78.145]) (envelope-sender ) by mail8.sea5.speakeasy.net (qmail-ldap-1.03) with SMTP for ; 20 Jul 2009 11:02:53 -0000 Received: from lowell-desk.lan (lowell-desk.lan [172.30.250.6]) by be-well.ilk.org (Postfix) with ESMTP id 3205F5080A; Mon, 20 Jul 2009 07:02:46 -0400 (EDT) Received: by lowell-desk.lan (Postfix, from userid 1147) id 604C31CC22; Mon, 20 Jul 2009 07:02:46 -0400 (EDT) To: Glen Barber References: <4ad871310907191717g1ed90be7y92250f2addc38d43@mail.gmail.com> From: Lowell Gilbert Date: Mon, 20 Jul 2009 07:02:46 -0400 In-Reply-To: <4ad871310907191717g1ed90be7y92250f2addc38d43@mail.gmail.com> (Glen Barber's message of "Sun\, 19 Jul 2009 20\:17\:22 -0400") Message-ID: <44tz17k46h.fsf@lowell-desk.lan> User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable 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 11:29:35 -0000 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' sh= ell." > > Can someone enlighten me if I am wrong about this? The person to whom you were responding had it closer. The shell specified in the "#!" first line is only consulted if you run it as "./foo.sh". Otherwise, it's input to the shell that you started, and the line is only a comment.