在linux 中,如何獲取指定目錄的父目錄呢?linux
我把該功能封裝成了一個簡單的函數:sql
- fadir()
- {
- local this_dir=`pwd`
- local child_dir="$1"
- dirname "$child_dir"
- cd $this_dir
- }
應用:shell
好比我想獲取 /opt/abc/whuang 的父目錄,則在shell 腳本中 這樣編寫:ide
father_dir=`fadir "/opt/abc/whuang"`函數
echo "father directory is $father_dir ."this
注意:linux 中的函數的返回值只能是0-255,不能是負數或字符串。spa