Last active
August 26, 2019 15:02
-
-
Save LozanoMatheus/da96b4e44b89b13ad4af10ac4602ad99 to your computer and use it in GitHub Desktop.
Bash/Shell - Getting the script paths (full and relative paths)
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
#!/usr/bin/env bash | |
RELATIVE_PATH="${0}" | |
RELATIVE_DIR_PATH="$(dirname "${0}")" | |
FULL_DIR_PATH="$(realpath "${0}" | xargs dirname)" | |
FULL_PATH="$(realpath "${0}")" | |
echo "RELATIVE_PATH->${RELATIVE_PATH}<-" | |
echo "RELATIVE_DIR_PATH->${RELATIVE_DIR_PATH}<-" | |
echo "FULL_DIR_PATH->${FULL_DIR_PATH}<-" | |
echo "FULL_PATH->${FULL_PATH}<-" | |
# ## Output | |
# RELATIVE_PATH->./bin/startup.sh<- | |
# RELATIVE_DIR_PATH->./bin<- | |
# FULL_DIR_PATH->/opt/my_app/bin<- | |
# FULL_PATH->/opt/my_app/bin/startup.sh<- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment