You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Variable transformation does not work with arrays #1081
Using "${array[@]@Q}" does not work as expected (I tried some other operators as well and assume this applies to all operators, not just @Q specifically).
$ bash -c 'var="with space"; echo "${var@Q}"''with space'
$ : works as expected
$ gosh -c 'var="with space"; echo "${var@Q}"''with space'
$ bash -c 'var=("some" "with space"); echo "${var[@]@Q}"''some' 'with space'
$ : does not work as expected
$ gosh -c 'var=("some" "with space"); echo "${var[@]@Q}"'some with space
As you can see, in the last line the result is not quoted.
Ah, it seems you are right about only Q and E being supported. I remember trying @K as well, but it seems it did not error because I tried it for arrays. The following "succeeds" in the sense that it does not error, but the output is still wrong (which makes sense if expansion operators are just ignored for arrays)
$ gosh -c 'var=("some" "with space"); echo "${var[@]@K}"'some with space
Activity
theclapp commentedon Jul 5, 2024
For the unaware (such as myself): The
${parameter@operator}is not in my local bash man page, I had to go looking for it. It came out in bash 4.4, circa late 2015. See https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html and search for${parameter@operator}.The
@Qoperator:There are 9 other operators defined in the GNU Bash documentation. This package handles only
@Qand@E, everything else panics. Seesh/expand/param.go
Lines 315 to 337 in 793d364
Edit: And, obviously, it doesn't work for arrays, regardless.
PigeonF commentedon Jul 5, 2024
Ah, it seems you are right about only
QandEbeing supported. I remember trying@Kas well, but it seems it did not error because I tried it for arrays. The following "succeeds" in the sense that it does not error, but the output is still wrong (which makes sense if expansion operators are just ignored for arrays)expand: apply per-element operators to quoted array expansions
interp: add test cases for ${var@op} on arrays
expand: implement ${var@op} operators on arrays like Bash