Last active
September 28, 2018 03:43
-
-
Save ryenus/88bc355515ce657b2da1d8ce1c16e4f9 to your computer and use it in GitHub Desktop.
portable readlink_f implementation
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
readlink_f() { | |
local _dir _path="$1" | |
[ -d "$_path" ] && _path=$(cd "$_path"; pwd -P) | |
while [ -L "$_path" ]; do | |
_dir=$(dirname "$_path") | |
_path=$(readlink "$_path") | |
[ -n "${_path##/*}" ] && _path="${_dir}/${_path}" | |
done | |
[ -f "$_path" ] && _path="$(cd "$(dirname "$_path")"; pwd -P)/${_path##*/}" | |
echo "${_path%/}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related: