加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

选择$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设置为任意值.
另一方面,如果没有涉及到命名文件,$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的.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读