Bash – Get Current Directory or Folder Name (Without Full Path) In Bash Script
No need for basename, and especially no need for a subshell running pwd (which adds an extra, and expensive, fork operation); the shell can do this internally using parameter expansion: result=${PWD##*/} # to assign to a variable result=${result:-/} # to correct for the case where PWD=/ printf ‘%s\n’ “${PWD##*/}” # to print to stdout # … Read more