选择$0和BASH_SOURCE之间
发布时间:2020-12-16 01:29:10 所属栏目:安全 来源:网络整理
导读:在“$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 she
在“$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设置为任意值. 以下示例说明了这一点: 脚本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的. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |