Created
February 3, 2016 13:31
-
-
Save leodutra/795fa027e273fffe5b8b to your computer and use it in GitHub Desktop.
Getting absolute path of a shell / bash script file in execution time
This file contains 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
#!/bin/bash | |
# REFERENCE: http://stackoverflow.com/a/1638397/1260526 | |
# Absolute path to this script, e.g. /home/user/bin/foo.sh | |
SCRIPT=$(readlink -f "$0") | |
# Absolute path this script is in, thus /home/user/bin | |
SCRIPTPATH=$(dirname "$SCRIPT") | |
echo $SCRIPTPATH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use the built-in
$BASH_SOURCE
env var too