linux 獲取指定目錄的父目錄

在linux 中,如何獲取指定目錄的父目錄呢?linux

我把該功能封裝成了一個簡單的函數:sql

 

  
  
           
  
  
  1. fadir()  
  2. {  
  3.     local this_dir=`pwd`  
  4.     local child_dir="$1" 
  5.     dirname "$child_dir" 
  6.     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

相關文章
相關標籤/搜索