From 3e3e297719fa7998bab8212e075c6ccc67ccdcfd Mon Sep 17 00:00:00 2001 From: Yannis Damigos Date: Tue, 1 Mar 2016 12:31:29 +0200 Subject: zephyr-env.sh: Fixed sourcing the project environment file In zsh the value of $0 depends on the FUNCTION_ARGZERO option which is set by default. FUNCTION_ARGZERO, when it is set, sets $0 temporarily to the name of the function/script when executing a shell function or sourcing a script. POSIX_ARGZERO option, when it is set, exposes the original value of $0 in spite of the current FUNCTION_ARGZERO setting. This patch allows to source the project environment file from both zsh and bash. It also removes the -z option from the basename command which is missing in OS X. Change-Id: I5a32404784d9064bf749fa58b4d73d4b56c908c2 Signed-off-by: Yannis Damigos --- zephyr-env.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/zephyr-env.sh b/zephyr-env.sh index 40b20a568..3722f7729 100644 --- a/zephyr-env.sh +++ b/zephyr-env.sh @@ -14,7 +14,24 @@ # limitations under the License. # -if [ "X$(basename -z -- "$0")" "==" "Xzephyr-env.sh" ]; then +# In zsh the value of $0 depends on the FUNCTION_ARGZERO option which is +# set by default. FUNCTION_ARGZERO, when it is set, sets $0 temporarily +# to the name of the function/script when executing a shell function or +# sourcing a script. POSIX_ARGZERO option, when it is set, exposes the +# original value of $0 in spite of the current FUNCTION_ARGZERO setting. +if [ -n "$ZSH_VERSION" ]; then + if [ $options[posixargzero] != "on" ]; then + setopt posixargzero + NAME=$(basename -- "$0") + setopt posixargzero + else + NAME=$(basename -- "$0") + fi +else + NAME=$(basename -- "$0") +fi + +if [ "X$NAME" "==" "Xzephyr-env.sh" ]; then echo "Source this file (do NOT execute it!) to set the Zephyr Kernel environment." exit fi -- cgit v1.2.3