shell获取当前目录名的几种方法
1.basename basename `pwd` 2.echo You can use parameter substitution with the ${var##pattern} syntax, which removes from $var the longest part of $Pattern that matches the front end of $var. Take a look at an example: echo ${PWD##*/} 3.awk A more elaborate solution uses a combination of awk (a pattern-scanning utility) and rev (a utility that reverses lines from a file or from stdin): cd /usr/share/cups/data pwd | rev | awk –F \/ '{print $1}' | rev data It's a lot easier to understand this kind of script step by step: pwd /usr/share/cups/data pwd | rev atad/supc/erahs/rsu/ pwd | rev | awk –F \/