bash – 获取shell脚本目录的父目录
发布时间:2020-12-16 01:28:11 所属栏目:安全 来源:网络整理
导读:参见英文答案 Getting the source directory of a Bash script from within52个 我这里有一个shell脚本: /node_modules/.bin/exec.sh 在exec.sh脚本中,我想获取包含脚本的目录的父目录的路径(不是pwd / cwd!).我可以像这样获取包含目录: `dirname $0` 这
参见英文答案 >
Getting the source directory of a Bash script from within52个
我这里有一个shell脚本: /node_modules/.bin/exec.sh 在exec.sh脚本中,我想获取包含脚本的目录的父目录的路径(不是pwd / cwd!).我可以像这样获取包含目录: `dirname $0` 这将产生: /node_modules/.bin 但我希望在一个目录更高,我只想得到 /node_modules 我无法找到答案,我的猜测是: `dirname $1` 但只是一个猜测,不确定这是否正确.任何人都可以解释如何做到这一点以及它是如何工作的?
运行dirname两次(嵌套).
~$dirname $PWD /home ~$dirname `dirname $PWD` / ~$ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |