Skip to content

Instantly share code, notes, and snippets.

@jonjack
Created October 1, 2018 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonjack/a1089064f41553b3937aa8815e878dda to your computer and use it in GitHub Desktop.
Save jonjack/a1089064f41553b3937aa8815e878dda to your computer and use it in GitHub Desktop.
Shell function to return the absolute path of some arbitrary one
#!/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