test -v difference between bash 5.1 and 5.2

2023-08-29 Thread Christian Schneider
Hi all, not sure if this intended or not, but in bash 5.2-p15 one of our scripts is broken. it is related to test -v, that checks, if a variable is set together with arrays. I condensed it to following example: #!/bin/bash declare -A foo foo=(["a"]="b" ["c"]="d") declare -a bar bar=("a" "b"

Re: test -v difference between bash 5.1 and 5.2

2023-08-29 Thread Chet Ramey
On 8/29/23 10:32 AM, Christian Schneider wrote: Hi all, not sure if this intended or not, but in bash 5.2-p15 one of our scripts is broken. it is related to test -v, that checks, if a variable is set together with arrays. Yes. Bash-5.2 allows test -v assoc[@] to test whether an associative a

Re: test -v difference between bash 5.1 and 5.2

2023-08-29 Thread Kerin Millar
Hi, On Tue, 29 Aug 2023 16:32:36 +0200 Christian Schneider wrote: > Hi all, > > not sure if this intended or not, but in bash 5.2-p15 one of our scripts > is broken. it is related to test -v, that checks, if a variable is set > together with arrays. > > I condensed it to following example: >

Re: test -v difference between bash 5.1 and 5.2

2023-08-29 Thread Chet Ramey
On 8/29/23 11:30 AM, Kerin Millar wrote: Hi, On Tue, 29 Aug 2023 16:32:36 +0200 Christian Schneider wrote: Hi all, not sure if this intended or not, but in bash 5.2-p15 one of our scripts is broken. it is related to test -v, that checks, if a variable is set together with arrays. I condense

Re: test -v difference between bash 5.1 and 5.2

2023-08-29 Thread Kerin Millar
On Tue, 29 Aug 2023 11:24:43 -0400 Chet Ramey wrote: > If you want to check whether an array variable is set, you can check > whether it has any set elements: > > (( ${#assoc[@]} > 0 )) This doesn't check whether an "array variable is set". Not only that, but the test will be true in the case

Re: test -v difference between bash 5.1 and 5.2

2023-08-29 Thread Kerin Millar
On Tue, 29 Aug 2023 11:34:21 -0400 Chet Ramey wrote: > On 8/29/23 11:30 AM, Kerin Millar wrote: > > Hi, > > > > On Tue, 29 Aug 2023 16:32:36 +0200 > > Christian Schneider wrote: > > > >> Hi all, > >> > >> not sure if this intended or not, but in bash 5.2-p15 one of our scripts > >> is broken.

Re: test -v difference between bash 5.1 and 5.2

2023-08-29 Thread Chet Ramey
On 8/29/23 11:38 AM, Kerin Millar wrote: On Tue, 29 Aug 2023 11:24:43 -0400 Chet Ramey wrote: If you want to check whether an array variable is set, you can check whether it has any set elements: (( ${#assoc[@]} > 0 )) This doesn't check whether an "array variable is set". It checks wheth

Re: test -v difference between bash 5.1 and 5.2

2023-08-29 Thread Kerin Millar
On Tue, 29 Aug 2023 11:44:13 -0400 Chet Ramey wrote: > On 8/29/23 11:38 AM, Kerin Millar wrote: > > On Tue, 29 Aug 2023 11:24:43 -0400 > > Chet Ramey wrote: > > > >> If you want to check whether an array variable is set, you can check > >> whether it has any set elements: > >> > >> (( ${#assoc[

Re: test -v difference between bash 5.1 and 5.2

2023-08-29 Thread Chet Ramey
On 8/29/23 11:56 AM, Kerin Millar wrote: One hopes that the shell programmer knows what variable types he's using, and uses the appropriate constructs. Some elect to source shell code masquerading as configuration data (or are using programs that elect to do so). Otherwise, yes, definitely.