Get Current Directory Name Without Path In Bash

Posted by Weston Ganger on April 01, 2016

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

Related External Links:

Posted in Linux and Tagged with bash script linux command-line 

Want me to help develop your next project or application?

Contact Us

Specializing in Ruby-on-Rails, Javascript, Multi-Platform Electron Desktop Apps and Hybrid Cordova Mobile Apps.

Recommended Posts