Skip to content

Commit

Permalink
[doc] Describe ${x@a} in doc/ref/chap-word-lang
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Dec 31, 2024
1 parent 16d9de6 commit 13491ca
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions doc/ref/chap-word-lang.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,30 @@ string:
$ unset -v x
$ echo "value = $x, quoted = ${x@Q}."
value = , quoted = .

---

`${x@a}` returns the set of characters that represent the attributes of the
variable in which each resulting string is stored.

- `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 obtained
value. For example, `${a[0]@a}` returns `a` because the string `${a[0]}` would
be obtained from an array although the resulting value of `${a[0]}` is a scalar
string.

$ echo ${a[0]@a}
a

When `$x` would result in a word list (such as `${a[@]}` and `${!ref}` with
`ref="a[@]"`), `${x@a}` returns a word list containing the attributes for each
word.

$ a=(1 2 3)
$ echo "${a[@]@a}"
a a a

0 comments on commit 13491ca

Please sign in to comment.