Extract the last directory of a pwd output
Using awk:
pwd | awk -F/ '{print $NF}'
Should work for you:
pwd | rev | cut -f1 -d'/' - | rev
Reference: https://stackoverflow.com/a/31728689/663058
Are you looking for basename or dirname?
Something like
basename "`pwd`"
should be what you want to know.
If you insist on using sed
, you could also use
pwd | sed 's#.*/##'
If you want to do it completely within a bash script without running any external binaries, ${PWD##*/}
should work.