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

bash – 什么是间接扩展? ${!var *}是什么意思?

发布时间:2020-12-15 19:56:16 所属栏目:安全 来源:网络整理
导读:我正在阅读“初学者的Bash指南”。它说: If the first character of PARAMETER is an exclamation point,Bash uses the value of the variable formed from the rest of PARAMETER as the name of the variable; this variable is then expanded and that v
我正在阅读“初学者的Bash指南”。它说:

If the first character of PARAMETER is an exclamation point,Bash uses the value of the variable formed from the rest of PARAMETER as the name of the variable; this variable is then expanded and that value is used in the rest of the substitution,rather than the value of PARAMETER itself. This is known as indirect expansion.

给出的例子是:

06000

我不太明白这里:

the value of the variable formed from the rest of PARAMETER

由于PARAMETER只是!N *,那么

the rest of PARAMETER

只是N *。这可以形成一个变量吗? Bash找到了所有可能的命令吗?

如果你阅读了bash手册页,它基本上证实了你所说的话:

If the first character of parameter is an exclamation point (!),a level of variable indirection is introduced. Bash uses the value of the variable formed from the rest of parameter as the name of the variable; this variable is then expanded and that value is used in the rest of the substitution,rather than the value of parameter itself. This is known as indirect expansion.

然而,从那里读:

The exceptions to this are the expansions of ${!prefix*} and ${!name[@]} described below.

${!prefix*} Names matching prefix. Expands to the names of variables whose names begin with prefix,separated by the first character of the IFS special variable.

换句话说,您的特定示例$ {!N *}是您引用的规则的一个例外。但是,它可以按预期的情况发布,如:

$ export xyzzy=plugh ; export plugh=cave

$ echo ${xyzzy}  # normal,xyzzy to plugh
plugh

$ echo ${!xyzzy} # indirection,xyzzy to plugh to cave
cave

(编辑:李大同)

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

    推荐文章
      热点阅读