A new ${...} syntax has been added in Bash 4.4, which looks like this: ${[email protected]}. Depending on the operator, its expanded value may be parameter the value of the parameter passes some kind of converted value, or it may be some kind of information about the parameter parameter itself. This sentence is too abstract, or see the detailed explanation below.
operator altogether has 5 kinds of values, namely Q, E, P, A, a, are single letters.
Q
Quote's abbreviation, the function of this operator is to add the value of the parameter to the appropriate quotation marks, which translates into a reusable (reusable) string form in the script:
|
$ foo=1
$ echo ${[email protected]}
' 1 ' # originally Foo has a value of only 1 this character, the converted value has three characters "' 1 '"
$ echo ${[email protected]}
$ ' \t\n ' because there are non-printable characters in the IFS, the converted value automatically uses the ANSI escape form of quotation marks $ ' ... ', and the characters inside are also used in the form of a backslash escape |
E
Escape's abbreviation, the function of this operator is to put the parameter value contained in the escape sequence Jiayi (unescape), as if to put the value of parameter in the $ ' ... ' As in the middle:
|
$ Foo= ' \u4e00 '
$ echo $foo
The value of \u4e00 # Foo contains 6 characters, just an escape sequence
$ echo ${[email protected]}
One # recognizes and transforms the escape sequence in the value of Foo, as if it were executed with echo $ ' \u4e00 ' |
P
Prompt's abbreviation, the function of this operator is to put the value of parameter according to the prompt variable (PS1 ... ) Escape rules, just like Bash Jiayi PS1 ... The same:
|
$ Foo= ' Prompt-\s-\v\$ '
$ echo ${[email protected]}
The prompt-bash-4.4$ # \s turned Bash,\v into a 4.4,\$ into $ |
A
Assignment's abbreviation, the function of this operator is to convert the value of parameter together with its name into the form of a reusable assignment statement, and if parameter has any attributes, it is further converted to declare The command declares the variable (with the corresponding attribute) in the form of:
|
$ foo=1
$ echo ${[email protected]}
foo= ' 1 ' # most common assignment statement
$ readonly Foo # add R property to Foo
$ echo ${[email protected]}
Declare-r foo= ' 1 ' # declare command form
$ export Foo # to Foo plus x attribute
$ echo ${[email protected]}
Declare-rx foo= ' 1 ' # becomes two properties rx |
A
Attributes's abbreviation, this operator function is to get all the properties of parameter:
|
$ Declare-irtu foo=1
$ echo ${[email protected]}
Irtu |
Array
If parameter is an array with a [*] or [@] subscript, then if operator is one of the Qepa, then the returned value is a list, the values in the list correspond to each element in the original array, and if operator is a, a declare sound is returned. String in the form of a Ming array:
|
$ readonly foo= (1 "$IFS" bar)
$ echo ${foo[@]@q}
' 1 ' $ ' \t\n ' bar
$ echo ${foo[@]@a}
Declare-ar foo= ([0]= "1" [1]=$ ' \t\n ' [2]= "bar") |
New ${[email protected]} syntax added in Bash 4.4