]> git.corax.cc Git - toolbox/commitdiff
toolbox.sh: Don't mask realpath's return value
authorMatthias Kruk <m@m10k.eu>
Thu, 22 Dec 2022 04:38:06 +0000 (13:38 +0900)
committerMatthias Kruk <m@m10k.eu>
Thu, 22 Dec 2022 04:38:06 +0000 (13:38 +0900)
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

index b234b8d74c2904e0d5016961155dbe38e19192bd..8df68adaf128128236254f7ee740b9d05c1a1b16 100644 (file)
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
 __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