bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bash tries to parse comsub in quoted PE pattern


From: Zachary Santer
Subject: Re: bash tries to parse comsub in quoted PE pattern
Date: Wed, 18 Oct 2023 08:19:35 -0400

On Tue, Oct 17, 2023 at 5:56 PM Emanuele Torre <torreemanuele6@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.

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")

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?

Zack


reply via email to

[Prev in Thread] Current Thread [Next in Thread]