From 8bc0c27ab2d88d718a6b0f100313406cee215fc3 Mon Sep 17 00:00:00 2001 From: quak Date: Thu, 29 Jan 2026 15:06:39 +0100 Subject: [PATCH] (bash) robust way to get path to script --- bash-test.sh | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/bash-test.sh b/bash-test.sh index 150eca7..b7ae015 100755 --- a/bash-test.sh +++ b/bash-test.sh @@ -1,10 +1,15 @@ #!/usr/bin/env bash -if ! $(which navig &>/dev/null); then - echo "command not found" - return 1 +# NOTE: this is way simpler +echo $(realpath "${BASH_SOURCE}") + +# NOTE: this is useless +if [[ "${0}" == "${BASH_SOURCE}" ]]; then + root_dir="$(dirname "${0}")" + root_dir="$(realpath "${root_dir}")" +else + root_dir="$(dirname "${0}")/$(dirname "${BASH_SOURCE}")" + root_dir="$(realpath "${root_dir}")" fi -function bash_source_test_function { - echo "sourcing not interrupted" -} +echo ${root_dir}