Re: wrong variable name in error message about unbound variable?

2023-10-19 Thread alex xmb sw ratchev
On Thu, Oct 19, 2023, 16:58 Chet Ramey wrote: > On 10/17/23 3:32 PM, Grisha Levit wrote: > > > The reason is that if there was no variable found prior to expanding > > the subscript, bash does not check to see if one was created during > > that process. > > Thanks, I'll consider it. Behavior

Re: wrong variable name in error message about unbound variable?

2023-10-19 Thread Chet Ramey
On 10/17/23 3:32 PM, Grisha Levit wrote: The reason is that if there was no variable found prior to expanding the subscript, bash does not check to see if one was created during that process. Thanks, I'll consider it. Behavior varies across shells in this area. Chet -- ``The lyf so short,

Re: wrong variable name in error message about unbound variable?

2023-10-17 Thread Grisha Levit
On Tue, Oct 17, 2023, 10:48 Christoph Anton Mitterer wrote: > > On Tue, 2023-10-17 at 00:26 -0400, Grisha Levit wrote: > > The array subscript can an arbitrary arithmetic expression with side > > effects, so it makes sense to perform the expansion even if the array > > whose subscript is being

Re: wrong variable name in error message about unbound variable?

2023-10-17 Thread Lawrence Velázquez
On Tue, Oct 17, 2023, at 10:48 AM, Christoph Anton Mitterer wrote: > As Lawrence pointed out: > $ set -u > $ declare -A a > $ echo ${a[k]} > bash: a[k]: unbound variable > > Here it actually looks first at a (which turns out to be an associative > array) and thus doesn't even bother to evaluate

Re: wrong variable name in error message about unbound variable?

2023-10-17 Thread Christoph Anton Mitterer
On Tue, 2023-10-17 at 00:26 -0400, Grisha Levit wrote: > The array subscript can an arbitrary arithmetic expression with side > effects, so it makes sense to perform the expansion even if the array > whose subscript is being expanded is unset: Okay... that's all pretty convoluted. I assume it

Re: wrong variable name in error message about unbound variable?

2023-10-17 Thread alex xmb sw ratchev
On Tue, Oct 17, 2023, 16:30 Chet Ramey wrote: > On 10/17/23 8:43 AM, Zachary Santer wrote: > > On Tue, Oct 17, 2023 at 8:00 AM Greg Wooledge wrote: > > > >> unicorn:~$ unset -v a b c array > >> unicorn:~$ a=b b=c c=42 array[a]=foo; declare -p array > >> declare -a

Re: wrong variable name in error message about unbound variable?

2023-10-17 Thread Chet Ramey
On 10/17/23 8:43 AM, Zachary Santer wrote: On Tue, Oct 17, 2023 at 8:00 AM Greg Wooledge wrote: unicorn:~$ unset -v a b c array unicorn:~$ a=b b=c c=42 array[a]=foo; declare -p array declare -a array=([42]="foo") What? What is Bash doing here? Dereferencing iteratively until

Re: wrong variable name in error message about unbound variable?

2023-10-17 Thread alex xmb sw ratchev
On Tue, Oct 17, 2023, 15:09 Zachary Santer wrote: > On Tue, Oct 17, 2023 at 8:43 AM Zachary Santer wrote: > > > On Tue, Oct 17, 2023 at 8:00 AM Greg Wooledge wrote: > > > >> unicorn:~$ unset -v a b c array > >> unicorn:~$ a=b b=c c=42 array[a]=foo; declare -p array > >> declare -a

Re: wrong variable name in error message about unbound variable?

2023-10-17 Thread Zachary Santer
On Tue, Oct 17, 2023 at 8:43 AM Zachary Santer wrote: > On Tue, Oct 17, 2023 at 8:00 AM Greg Wooledge wrote: > >> unicorn:~$ unset -v a b c array >> unicorn:~$ a=b b=c c=42 array[a]=foo; declare -p array >> declare -a array=([42]="foo") >> > What? What is Bash doing here?

Re: wrong variable name in error message about unbound variable?

2023-10-17 Thread Zachary Santer
On Tue, Oct 17, 2023 at 8:00 AM Greg Wooledge wrote: > unicorn:~$ unset -v a b c array > unicorn:~$ a=b b=c c=42 array[a]=foo; declare -p array > declare -a array=([42]="foo") > What? What is Bash doing here? Dereferencing iteratively until it finds something it can do arithmetic

Re: wrong variable name in error message about unbound variable?

2023-10-17 Thread Greg Wooledge
On Tue, Oct 17, 2023 at 04:46:22AM +0200, Christoph Anton Mitterer wrote: > But why does it even try to evaluate the subscript "key" as arithmetic > expression? Because that's how indexed arrays work. Everything inside the square brackets is an arithmetic expression, and in an arithmetic

Re: wrong variable name in error message about unbound variable?

2023-10-16 Thread Grisha Levit
On Mon, Oct 16, 2023, 22:46 Christoph Anton Mitterer wrote: > Hey. > > On Mon, 2023-10-16 at 22:05 -0400, Lawrence Velázquez wrote: > > Under no circumstances should your examples complain about "array" > > because they do not attempt to expand it. As I demonstrated, your > > examples do not

Re: wrong variable name in error message about unbound variable?

2023-10-16 Thread Christoph Anton Mitterer
Hey. On Mon, 2023-10-16 at 22:05 -0400, Lawrence Velázquez wrote: > Under no circumstances should your examples complain about "array" > because they do not attempt to expand it.  As I demonstrated, your > examples do not even complain about unset scalar variables. Okay I realise now, why it

Re: wrong variable name in error message about unbound variable?

2023-10-16 Thread Lawrence Velázquez
On Mon, Oct 16, 2023, at 9:06 PM, Christoph Anton Mitterer wrote: > $ set -u > $ [ -n "${array[key]+is_set}" ] && echo is set || echo not set > bash: key: unbound variable > $ [[ -v array[key] ]] && echo is set || echo not set > bash: key: unbound variable Since "array" has not been declared at

wrong variable name in error message about unbound variable?

2023-10-16 Thread Christoph Anton Mitterer
Hey. On 5.2.15 I've noticed the following: $ set -u $ [ -n "${array[key]+is_set}" ] && echo is set || echo not set bash: key: unbound variable $ [[ -v array[key] ]] && echo is set || echo not set bash: key: unbound variable $ declare -A array $ [ -n "${array[key]+is_set}" ] && echo is set ||