Last active
December 4, 2015 10:07
-
-
Save antonfisher/fb8a9bdb4b9fc2d44134 to your computer and use it in GitHub Desktop.
BASH: get_full_file_path
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
## | |
# Get full file/directory path | |
# | |
# Examples: | |
# full_path=$(get_full_path '/tmp'); # /tmp | |
# full_path=$(get_full_path '~/..'); # /home | |
# full_path=$(get_full_path '../../../'); # /home | |
# | |
# @param {String} $1 - relative path | |
# @returns {String} absolute path | |
# | |
function get_full_path { | |
local user_home; | |
local user_home_sed; | |
local rel_path; | |
local result; | |
user_home="${HOME//\//\\\/}"; | |
user_home_sed="s#~#${user_home}#g"; | |
rel_path=$( echo "${1}" | sed "${user_home_sed}" ); | |
result=$( readlink -e "${rel_path}" ); | |
echo "${result}"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment