If the first character of
PARAMETER
is an exclamation point,Bash uses the value of the variable formed from the rest ofPARAMETER
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 ofPARAMETER
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找到了所有可能的命令吗?
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 theIFS
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