Created
September 4, 2020 13:31
-
-
Save mmguero/007a129fe298ff9f1cf936c3914eb95e to your computer and use it in GitHub Desktop.
determine script path in a bash script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
[[ "$(uname -s)" = 'Darwin' ]] && REALPATH=grealpath || REALPATH=realpath | |
[[ "$(uname -s)" = 'Darwin' ]] && DIRNAME=gdirname || DIRNAME=dirname | |
if ! (type "$REALPATH" && type "$DIRNAME") > /dev/null; then | |
echo "$(basename "${BASH_SOURCE[0]}") requires $REALPATH and $DIRNAME" | |
exit 1 | |
fi | |
SCRIPT_PATH="$($DIRNAME $($REALPATH -e "${BASH_SOURCE[0]}"))" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment