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