博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux bash脚本_如何在Linux上的Bash中可靠地获取脚本目录?
阅读量:2517 次
发布时间:2019-05-11

本文共 870 字,大约阅读时间需要 2 分钟。

linux bash脚本

How to get a ’s directory reliably in Bash on ?

如何在 Bash中可靠地获取的目录?

For example, to get the directory of the executing script $0.

例如,获取执行脚本$0的目录。

can give you .

可以为您提供 。

You can get the absolute path of the script by to handle symbolic links (consider a symbolic link ./run.sh linked to ../../run.sh, dirname ./run.sh will give you .), and then pass the absolute path to dirname.

您可以通过获取脚本的绝对路径来处理符号链接(考虑链接到../../run.sh的符号链接./run.sh, dirname ./run.sh会为您提供. ) ,然后将绝对路径传递到dirname

In summary, the script the get the directory of current script is:

总之,获取当前脚本目录的脚本是:

directory=$(dirname $(readlink -f $0))

or

要么

directory=$(dirname $(readlink -f ${BASH_SOURCE[0]}))

to also handle sourced bash script. Check for details of the ${BASH_SOURCE[0]} meaning.

还可以处理源bash脚本。 有关${BASH_SOURCE[0]}含义的详细信息,请查看 。

Answered by Eric Z Ma.
埃里克·马(Eric Z Ma)回答。

翻译自:

linux bash脚本

转载地址:http://kplwd.baihongyu.com/

你可能感兴趣的文章
codevs 1163:访问艺术馆
查看>>
冲刺Noip2017模拟赛3 解题报告——五十岚芒果酱
查看>>
并查集
查看>>
sessionStorage
查看>>
代码示例_进程
查看>>
Java中关键词之this,super的使用
查看>>
学习进度
查看>>
“此人不存在”
查看>>
github.com加速节点
查看>>
解密zend-PHP凤凰源码程序
查看>>
python3 序列分片记录
查看>>
Atitit.git的存储结构and 追踪
查看>>
atitit 读书与获取知识资料的attilax的总结.docx
查看>>
B站 React教程笔记day2(3)React-Redux
查看>>
找了一个api管理工具
查看>>
Part 2 - Fundamentals(4-10)
查看>>
使用Postmark测试后端存储性能
查看>>
NSTextView 文字链接的定制化
查看>>
第五天站立会议内容
查看>>
ATMEGA16 IOport相关汇总
查看>>