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

相关文章
相关标签/搜索