On Wed, Oct 18, 2023, 14:20 Zachary Santer <zsan...@gmail.com> wrote:
> On Tue, Oct 17, 2023 at 5:56 PM Emanuele Torre <torreemanue...@gmail.com> > wrote: > > > bash-5.1$ letters=( {a..z} ); echo "${letters["{10..15}"]}" > > k l m n o p > > > > Then there's the question "Was that even supposed to work like that?" If > so, you'd think it would generalize to being able to pass a series of > whitespace-delimited indices to an array expansion. > by chet stating many times that every bash item undergoes expansion .. like why [[ -v var[\$k] ]] .. cause $k once and if not \$ again in parsing the bash cmd / keyword / whatever In Bash 5.2: > $ array=( zero one two three four five six ) > $ printf '%s\n' "${array["{2..6..2}"]}" > two > four > six > $ printf '%s\n' "${array[{2..6..2}]}" > -bash: {2..6..2}: syntax error: operand expected (error token is > "{2..6..2}") > $ printf '%s\n' "${array["2 4 6"]}" > -bash: 2 4 6: syntax error in expression (error token is "4 6") > $ printf '%s\n' "${array[2 4 6]}" > -bash: 2 4 6: syntax error in expression (error token is "4 6") > $ printf '%s\n' "${array[2,4,6]}" > six > $ indices=(2 4 6) > $ printf '%s\n' "${array[${indices[@]}]}" > -bash: 2 4 6: syntax error in expression (error token is "4 6") > $ printf '%s\n' "${array[${indices[*]}]}" > -bash: 2 4 6: syntax error in expression (error token is "4 6") > u miss at least once the quotes of ['{blabla}'] Considering I don't think this is documented anywhere, and what's in > between the square brackets gets an arithmetic expansion applied to it, I'm > going to guess "no." > > So how important is it to maintain undocumented behavior? > > Why does "${#@}" expand to the same thing as "${#}"? Why is $[ ] > equivalent to $(( ))? Does that stuff need to continue to work forever? > its both the 1+ args $@ expands to different args "$@" to preserve spacesafe $* expands the same ( all args ) to one-arg "$*" spaceaafe Zack > x >