Extract the last directory of a pwd output

梦想与她 提交于 2019-11-30 04:16:17

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.

CenterOrbit

Should work for you: pwd | rev | cut -f1 -d'/' - | rev

Reference: https://stackoverflow.com/a/31728689/663058

Using awk:

pwd | awk -F/ '{print $NF}'
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!