Shell execution ( [was] Re: Value of $? lost in the beginning of a function.)

Glen Barber glen.j.barber at gmail.com
Mon Jul 20 00:17:24 UTC 2009


Possibly off-topic...


2009/7/19 Glen Barber <glen.j.barber at gmail.com>:
> 2009/7/19 Romain Tartière <romain at blogreen.org>:
>> 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.  sh 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' shell."

Can someone enlighten me if I am wrong about this?

-- 
Glen Barber


More information about the freebsd-stable mailing list