From 2d5b5d4fd765a7b3e3bb3f795fd75a226e2676e8 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Thu, 22 Dec 2022 13:38:06 +0900 Subject: [PATCH] toolbox.sh: Don't mask realpath's return value When determining the location of toolbox.sh, the result from realpath is passed to dirname to remove the script name from the path. However, both commands are executed in the same statement, causing the return value of realpath to be masked by dirname. This commit splits the statement into separate steps, so that return values are not masked. --- toolbox.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/toolbox.sh b/toolbox.sh index b234b8d..8df68ad 100644 --- a/toolbox.sh +++ b/toolbox.sh @@ -17,18 +17,21 @@ # along with this program. If not, see . __toolbox_init() { - local modpath + local toolboxpath + local toolboxroot - if ! modpath="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"; then + if ! toolboxpath=$(realpath "${BASH_SOURCE[0]}"); then echo "Could not determine toolbox path" 1>&2 return 1 fi - declare -gxr TOOLBOX_PATH="$modpath" + toolboxroot="${toolboxpath%/*}" + + declare -gxr TOOLBOX_PATH="$toolboxroot" declare -gxr TOOLBOX_HOME="$HOME/.toolbox" declare -axgr __TOOLBOX_MODULEPATH=( "$TOOLBOX_HOME/include" - "$modpath/include" + "$toolboxroot/include" ) declare -Axg __TOOLBOX_INCLUDED -- 2.47.3