Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 20 Jul 2009 13:56:11 -0400
From:      Lowell Gilbert <freebsd-stable-local@be-well.ilk.org>
To:        Glen Barber <glen.j.barber@gmail.com>
Cc:        stable@freebsd.org, Lowell Gilbert <freebsd-stable-local@be-well.ilk.org>
Subject:   Re: Shell execution ( [was] Re: Value of $? lost in the beginning of a function.)
Message-ID:  <44k523fdc4.fsf@be-well.ilk.org>
In-Reply-To: <4ad871310907200702q6d13a44bqaeb2242d65866b16@mail.gmail.com> (Glen Barber's message of "Mon\, 20 Jul 2009 10\:02\:23 -0400")
References:  <4ad871310907191717g1ed90be7y92250f2addc38d43@mail.gmail.com> <44tz17k46h.fsf@lowell-desk.lan> <4ad871310907200702q6d13a44bqaeb2242d65866b16@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Glen Barber <glen.j.barber@gmail.com> writes:

> Hi, Lowell
>
> On Mon, Jul 20, 2009 at 7:02 AM, Lowell
> Gilbert<freebsd-stable-local@be-well.ilk.org> wrote:
>> Glen Barber <glen.j.barber@gmail.com> writes:
>>
>>> Possibly off-topic...
>>>
>>>
>>> 2009/7/19 Glen Barber <glen.j.barber@gmail.com>:
>>>> 2009/7/19 Romain Tarti=E8re <romain@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. =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' =
shell."
>>>
>>> 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". =A0Otherwise, it's input to the shell that you started,
>> and the line is only a comment.
>>
>
> I suppose that makes sense, but what if the script location is in the
> user's $PATH?

That would be the same as "./foo.sh".=20=20
The distinction is between whether the file is treated as an executable
or as input to a script.  You might find the manual page for execve(2)
useful for more detail on how the former case is handled.





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?44k523fdc4.fsf>