perl – 你如何爬上bash脚本的父目录结构?
发布时间:2020-12-15 21:46:31 所属栏目:大数据 来源:网络整理
导读:是否有一种从脚本位置爬上多个目录级别的更简洁的方法. 这就是我现在拥有的. # get the full path of the scriptD=$(cd ${0%/*} echo $PWD/${0##*/})D=$(dirname $D)D=$(dirname $D)D=$(dirname $D)# second level parent directory of scriptecho $D 我希望
是否有一种从脚本位置爬上多个目录级别的更简洁的方法.
这就是我现在拥有的. # get the full path of the script D=$(cd ${0%/*} && echo $PWD/${0##*/}) D=$(dirname $D) D=$(dirname $D) D=$(dirname $D) # second level parent directory of script echo $D 我希望找到第n级的简洁方法.除了进行for循环之外的任何想法? 解决方法dir="/path/to/somewhere/interesting" saveIFS=$IFS IFS='/' parts=($dir) IFS=$saveIFS level=${parts[3]} echo "$level" # output: somewhere (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |