Thursday, 17 August 2017

Bash Print Directory Portion of a Path

Cited from the Book "Pro Bash Programming"

case $1 in
  */*) printf "%s\n" "${1%/*}" ;;
  *) [ -e "$1" ] && printf "%s\n" "$PWD" || echo '.' ;;
esac

No comments:

Post a Comment