[Buildroot] [PATCH 1/1] package/environment-setup/environment-setup: add zsh

Arnout Vandecappelle arnout at mind.be
Thu Sep 2 08:16:59 UTC 2021



On 01/09/2021 18:04, Krzysztof Kanas wrote:
> 
> 
> On 01/09/2021 16:59, Arnout Vandecappelle wrote:
>>
>>
>> On 01/09/2021 16:48, Krzysztof Kanas wrote:
>>>
>>>
>>> On 01/09/2021 15:26, Arnout Vandecappelle wrote:
>>>>
>>>>
>>>> On 30/08/2021 22:13, Krzysztof Kanas wrote:
>>>>> environment-setup used BASH_SOURCE which is bash specific and empty
>>>>> variable for zsh (and other shell's).
>>>>> Use $0 which should be work across multiple shells(tcsh, dash, zsh)
>>>>> It won't work if other script is sourcing environment-setup.
>>>>
>>>>    The environment-setup is supposed to be source'd, so how is this ever
>>>> going to
>>>> work?
>>> This script will work when sourced interactively from bash shell due the test
>>> for ${BASH_SOURCE} so this behavior is not changed.
>>>
>>> What I meant by this paragraph was how different shell's set $0 augment whether
>>> script is sourced interactively or sourced from another script, e.g:
>>> cat > foo.sh
>>> source environment-setup
>>> ^D
>>>
>>> But I missed case when environment-setup is sourced from another directory,
>>> lucky this works in zsh case, but not in case of dash, ksh.
>>> So the fix would be applicable to zsh only (actually my main purpose for the
>>> patch).
>>>
>>>>
>>>>    I think the only viable solution is to require an argument if shell is not
>>>> bash.
>>> So you are thinking of
>>> if [ $SHELL != bash ] ; then ?
>>
>>   I was thinking of your if [ x"${BASH_SOURCE}" != x"" ]
> 
> So what about:
> 
> if [ x"$BASH_VERSION" != x"" ] ; then
>         SDK_PATH=$(dirname $(realpath "${BASH_SOURCE[0]}"))
> elif [ x"$ZSH_VERSION" != x"" ] ; then
>         SDK_PATH=$(dirname $(realpath $0))
> else
>         echo 'unsuported shell
> fi
> 
> This should work for bash as previously add zsh support, but won't work for dash
> (as it didn't work previously ), but will give clearer error indication.

 LGTM, thanks!

 Regards,
 Arnout

> 
>>
>>   Regards,
>>   Arnout
>>
>>> I don't know if that will be easy/portable to do  b/c running,
>>>
>>> zsh
>>> bash
>>> env|grep SHELL
>>> SHELL=/bin/zsh
>>> XTERM_SHELL=/bin/zsh
>>>
>>>>
>>>>    Regards,
>>>>    Arnout
>>>>
>>>>>
>>>>> Signed-off-by: Krzysztof Kanas <kkanas at fastmail.com>
>>>>> ---
>>>>>    package/environment-setup/environment-setup | 6 +++++-
>>>>>    1 file changed, 5 insertions(+), 1 deletion(-)
>>>>>
>>>>> diff --git a/package/environment-setup/environment-setup
>>>>> b/package/environment-setup/environment-setup
>>>>> index e9bc36fdd093..2b54e88d6689 100644
>>>>> --- a/package/environment-setup/environment-setup
>>>>> +++ b/package/environment-setup/environment-setup
>>>>> @@ -16,4 +16,8 @@ Some tips:
>>>>>    * To build CMake-based projects, use the "cmake" alias
>>>>>      EOF
>>>>> -SDK_PATH=$(dirname $(realpath "${BASH_SOURCE[0]}"))
>>>>> +if [ x"${BASH_SOURCE}" != x"" ]; then
>>>>> +        SDK_PATH=$(dirname $(realpath "${BASH_SOURCE[0]}"))
>>>>> +else
>>>>> +    SDK_PATH=$(dirname $(realpath $0))
>>>>> +fi
>>>>>



More information about the buildroot mailing list