在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