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

Krzysztof Kanas kkanas at fastmail.com
Wed Sep 1 14:48:52 UTC 2021



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 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