Linux.com

Four ways to extract the current directory name

Posted by: Anonymous [ip: 147.88.200.144] on November 06, 2007 12:29 PM
An easier way or at least a shorter command than
pwd | rev | awk –F \/ '{print $1}' | rev
would be
pwd | awk -F \/ '{ print $NF }'

awk knows the variable $NF which contains the "number of fields" so { print $NF } gives you the last field


just my 2¢

#

Return to Four ways to extract the current directory name