Created
April 22, 2022 15:04
-
-
Save haeramkeem/72761bfb7dc455f222956e59c375e8b6 to your computer and use it in GitHub Desktop.
Get current directory name only
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# https://stackoverflow.com/a/1371283 | |
result=${PWD##*/} # to assign to a variable | |
printf '%s\n' "${PWD##*/}" # to print to stdout | |
# ...more robust than echo for unusual names | |
# (consider a directory named -e or -n) | |
printf '%q\n' "${PWD##*/}" # to print to stdout, quoted for use as shell input | |
# ...useful to make hidden characters readable. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment