Created
October 1, 2018 10:58
-
-
Save jonjack/a1089064f41553b3937aa8815e878dda to your computer and use it in GitHub Desktop.
Shell function to return the absolute path of some arbitrary one
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/sh | |
function abspath() { | |
pushd . > /dev/null; | |
if [ -d "$1" ]; then cd "$1"; dirs -l +0; | |
else cd "`dirname \"$1\"`"; cur_dir=`dirs -l +0`; | |
if [ "$cur_dir" == "/" ]; then echo "$cur_dir`basename \"$1\"`"; | |
else echo "$cur_dir/`basename \"$1\"`"; fi; fi; popd > /dev/null; | |
} | |
echo abspath ~ | |
echo "ABSPATH ~ = " && abspath ~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment