Skip to content

Instantly share code, notes, and snippets.

@hirose31
Created March 28, 2014 05:34
Show Gist options
  • Select an option

  • Save hirose31/9826054 to your computer and use it in GitHub Desktop.

Select an option

Save hirose31/9826054 to your computer and use it in GitHub Desktop.
abspath() {
_CWD=$(pwd)
if [ -d "$1" ]; then
\cd $1
echo $(pwd -P)/
elif [ -f "$1" ]; then
case $1 in
*/*) \cd ${1%/*};;
esac
echo $(pwd -P)/${1##*/}
else
echo $1
fi
\cd $_CWD
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment