选择$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]}
${BASH_SOURCE [0]}(或更简单地说,$BASH_SOURCE)包含所有调用方案中包含脚本的(潜在的相对)路径,特别是在脚本来源时,这对于$0不是真的.

此外,由于Charles Duffy指出,调用者可以将$0设置为任意值.
另一方面,如果没有涉及到命名文件,$BASH_SOURCE可以是空的;例如.:
echo’echo“[$BASH_SOURCE]”’|庆典

以下示例说明了这一点:

脚本foo:

#!/usr/bin/env bash
echo "[$0] vs. [${BASH_SOURCE[0]}]"
$bash ./foo
[./foo] vs. [./foo]

$. ./foo
[bash] vs. [./foo]

$0是POSIX shell规范的一部分,而名称建议的是BASH_SOURCE是特定于Bash的.

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...