1、获取当前目录
root@localhost:/home/file/download# pwd
/home/file/download
脚本中调用
current_path="$PWD" # 同 "`pwd`"
2、获取上一级目录
root@localhost:/home/file/download# dirname "$PWD"
/home/file
脚本中调用
path=$(dirname "$PWD") #或者`dirname $PWD`
3、获取上上级目录
root@localhost:/home/file/download# dirname $(dirname "$PWD")
/home
脚本中调用
path=$(dirname $(dirname "$PWD"))
4、获取目录的最后部分
root@localhost:/home/file/download# basename "$PWD"
download
脚本中调用
last_component=$(basename "$PWD")