diff --git a/doc/ref/chap-word-lang.md b/doc/ref/chap-word-lang.md index cecdb0839..2f82fb929 100644 --- a/doc/ref/chap-word-lang.md +++ b/doc/ref/chap-word-lang.md @@ -300,34 +300,89 @@ string: --- -`${x@a}` returns the set of characters that represent the attributes of -*h-value* of the expansion `$x`. +`${x@a}` returns characters that represent the attributes of the `${x}`, or +more precisely, the *h-value* of `${x}`. + +Definitions: + +- *h-value* is the variable (or the object that the variable directly points) + from which the result of `${x}` would originally come. +- *r-value* is the expansion of `${x}` + +For example, with `arr=(1 2 3)`: + + + + + +- thead + - Reference + - Expression + - H-value + - R-value + - Flags returned +- tr + - + - `${arr[0]@a}` or
`${arr@a}` + - array
`(1 2 3)` + - string
`1` + - `a` +- tr + - + - `${arr[@]@a}` + - array
`(1 2 3)` + - array
`(1 2 3)` + - `a a a` +- tr + - `ref=arr` or `ref=arr[0]` + - `${!ref@a}` + - array
`(1 2 3)` + - string
`1` + - `a` + - +- tr + - `ref=arr[@]` + - `${!ref@a}` + - array
`(1 2 3)` + - array
`(1 2 3)` + - `a a a` + +
+ +When `${x}` would result in a word list, `${x@a}` returns a word list +containing the attributes of the *h-value* of each word. -Here, *h-value* is the variable (or the object that the variable directly -points) from which the result of `$x` would originally come. This is different -from the *r-value* of the expansion `$x`, namely the result of the expansion -`$x`. - -The characters representing attributes are listed below: - -- `a`: The value of `$x` would be obtained from an indexed array element. -- `A`: The value of `$x` would be obtained from an associative array element. -- `r`: The value of `$x` would be obtained from a readonly container. -- `x`: The value of `$x` would be obtained from a container with the export attribute. -- `n`: `x` is a name reference (OSH extension) - -It should be noted that `${x@a}` does not return the attributes of the -*r-value* of the expansion `$x`. For example, although the *r-value* of -`${arr[0]}` is arr scalar string, `${arr[0]@a}` returns `a` because the -*h-value* is array `arr`, which stores the element `arr[0]`. - - $ echo ${arr[0]@a} - a - -When `$x` would result in a word list (such as `${arr[@]}` and `${!ref}` with -`ref="arr[@]"`), `${x@a}` returns a word list containing the attributes of the -*h-value* of each word. +--- - $ arr=(1 2 3) - $ echo "${arr[@]@a}" - a a a +These characters may be returned: + + + +- thead + - Character + - Where `${x}` would be obtained +- tr + - `a` + - indexed array +- tr + - `A` + - associative array +- tr + - `r` + - readonly container +- tr + - `x` + - exported variable +- tr + - `n` + - name reference (OSH extension) + +