Linux 获取指定目录的父目录

字体大小: 中小 标准 ->行高大小: 标准

在linux 中,如何获取指定目录的父目录呢?
 
我把该功能封装成了一个简单的函数:

  1. fadir() {
  2. local this_dir=`pwd` local child_dir="$1"
  3. dirname "$child_dir" cd $this_dir
  4. }

应用:
 
比如我想获取 /opt/abc/whuang 的父目录,则在shell 脚本中 这样编写:
 
father_dir=`fadir "/opt/abc/whuang"`
 
echo "father directory is  $father_dir ."
 
注意:linux 中的函数的返回值只能是0-255,不能是负数或字符串。

此文章由 http://www.ositren.com 收集整理 ,地址为: http://www.ositren.com/htmls/64762.html