(bash) robust way to get path to script

This commit is contained in:
2026-01-29 15:06:39 +01:00
parent faecef25ce
commit 8bc0c27ab2
+11 -6
View File
@@ -1,10 +1,15 @@
#!/usr/bin/env bash #!/usr/bin/env bash
if ! $(which navig &>/dev/null); then # NOTE: this is way simpler
echo "command not found" echo $(realpath "${BASH_SOURCE}")
return 1
# 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 fi
function bash_source_test_function { echo ${root_dir}
echo "sourcing not interrupted"
}