What is correct syntax to check for empty array? behavior diffs between 4.3 and 4.4

2017-01-26 Thread L A Walsh
I noticed an error coming out of a script when I tried to check an array's size w/unbound var checking enabled (note my=declare, array='my -a') First w/bash-4.3.42: bash# try in subshell in case '-u' exits array gv_ops=() echo ${#gv_ops[@]} # existing var 0

Re: What is correct syntax to check for empty array? behavior diffs between 4.3 and 4.4

2017-01-26 Thread Greg Wooledge
On Thu, Jan 26, 2017 at 01:11:25PM -0800, L A Walsh wrote: >> Subject: Re: What is correct syntax to check for empty array? The number of elements is 0 if the array is empty. So you would test whether ${#array[@]} is 0. > > set -u # now add an undefined check Now you've ch

Re: What is correct syntax to check for empty array? behavior diffs between 4.3 and 4.4

2017-01-26 Thread L A Walsh
Greg Wooledge wrote: On Thu, Jan 26, 2017 at 01:11:25PM -0800, L A Walsh wrote: Subject: Re: What is correct syntax to check for empty array? The number of elements is 0 if the array is empty. So you would test whether ${#array[@]} is 0. set -u # now add

bug in 4.4?

2017-01-26 Thread L A Walsh
If I set bash to complain about uninitialized variables w/-u, I get inconsistent, and seemingly incorrect behavior: echo $BASH_VERSION 4.4.5(1)-release set -u echo ${undefvar} bash: undefvar: unbound variable echo ${undefvar[@]} # no message about unb

Re: bug in 4.4?

2017-01-26 Thread Grisha Levit
This seems to be the following change (from CHANGES) > a. Using ${a[@]} or ${a[*]} with an array without any assigned elements when the nounset option is enabled no longer throws an unbound variable error. This mirrors the behavior of $@. On Jan 26, 2017 4:28 PM, "L A Walsh" wrote: If

Re: bug in 4.4?

2017-01-26 Thread L A Walsh
Grisha Levit wrote: This seems to be the following change (from CHANGES) > | a. Using ${a[@]} or ${a[*]} with an array without any assigned elements when the nounset option is enabled no longer throws an unbound variable error.| --- I see... Tnx! -l