help-bash
[Top][All Lists]
Advanced

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

Re: is it really required that arr['1']=bla gives syntax error instead o


From: Greg Wooledge
Subject: Re: is it really required that arr['1']=bla gives syntax error instead of parse '1' as 1
Date: Mon, 19 Jul 2021 11:55:32 -0400

On Mon, Jul 19, 2021 at 10:30:36AM -0500, Jesse Hathaway wrote:
> That does seem inconsistent with how bash treats double quoted array
> subscripts and variable subscripts.
> 
> all these work:
> 
>     arr["1"]=bar
>     one='1'
>     arr[$one]=foo
>     arr["$one"]=baz
> 

In <https://lists.gnu.org/archive/html/bug-bash/2021-02/msg00189.html>
Chet says that "The contents of (( are expanded as if they are between
double quotes".  I wonder if this generalizes to *all* arithmetic
contexts.

unicorn:~$ (( 4 + '1' ))
bash: ((: 4 + '1' : syntax error: operand expected (error token is "'1' ")
unicorn:~$ arr['1']=bla
bash: '1': syntax error: operand expected (error token is "'1'")
unicorn:~$ echo "${LOGNAME:'1'}"
bash: LOGNAME: '1': syntax error: operand expected (error token is "'1'")
unicorn:~$ let x='1'+2
unicorn:~$ echo "$x"
3
unicorn:~$ [[ 4 -gt '1' ]]
unicorn:~$ 

Hmm.  Not all of them, apparently.  Some of them.



reply via email to

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