(bash) robust way to get path to script
This commit is contained in:
+11
-6
@@ -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"
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user