bash获取当前目录的父目录 [英] bash get the parent directory of current directory
本文介绍了bash获取当前目录的父目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有这样的文件路径
/ home / smith / Desktop / Test
/ home / smith /桌面/测试/
如何更改字符串,以便获得父目录? / p>
例如
/ home / smith / Desktop
/ home / smith / Desktop /
解决方案
dir = / home / smith / Desktop / Test
parentdir =$(dirname$ dir)
如果还有一个尾部的斜线也可以。
If I have a file path as such
/home/smith/Desktop/Test
/home/smith/Desktop/Test/
how do I change the string so it will get the parent directory?
e.g.
/home/smith/Desktop
/home/smith/Desktop/
解决方案
dir=/home/smith/Desktop/Test
parentdir="$(dirname "$dir")"
Works if there is a trailing slash, too.
这篇关于bash获取当前目录的父目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文