相关疑难解决方法(0)

从脚本本身获取Bash脚本的源目录

如何获取其中的目录路径的Bash脚本位于,里面那个脚本?

例如,假设我想使用Bash脚本作为另一个应用程序的启动器.我想将工作目录更改为Bash脚本所在的目录,因此我可以对该目录中的文件进行操作,如下所示:

$ ./application

directory bash

4672
推荐指数
44
解决办法
158万
查看次数

在$ 0和BASH_SOURCE之间选择

如何在"$0"和之间做出选择"${BASH_SOURCE[0]}"

GNU的这个描述对我没什么帮助.

    BASH_SOURCE

 An array variable whose members are the source filenames where the
 corresponding shell function names in the FUNCNAME array variable are
 defined. The shell function ${FUNCNAME[$i]} is defined in the file
 ${BASH_SOURCE[$i]} and called from ${BASH_SOURCE[$i+1]}
Run Code Online (Sandbox Code Playgroud)

bash

84
推荐指数
4
解决办法
4万
查看次数

标签 统计

bash ×2

directory ×1