Get Current Directory Name Without Path In Bash

Posted by Weston Ganger

I was writing a script and wanted to get the current directory name without the path.

Heres a few ways to do this in Bash.


# Simple way to print it
echo "${PDW##*/}"

# More complicated but more reliable in case of weird directory names
printf '%s\n' "${PWD##*/}"

# Assign to a variable
result=${PWD##*/}


Related External Links:

Article Topic:Software Development - Linux

Date:April 01, 2016

Recommended Posts