Re: test -v for array does not work as documented

2020-02-23 Thread Chet Ramey
On 2/23/20 11:36 AM, pepa65 wrote: > On 23/02/2020 23.27, Chet Ramey wrote: >> On 2/21/20 3:31 AM, pepa65 wrote: >>> By the way, it seems that `local -p var` doesn't work like 'declare -p >>> var` even though `help local` suggests it should. >> >> How so? Do you mean that declare -p var in a

Re: test -v for array does not work as documented

2020-02-23 Thread pepa65
On 23/02/2020 23.27, Chet Ramey wrote: > On 2/21/20 3:31 AM, pepa65 wrote: >> By the way, it seems that `local -p var` doesn't work like 'declare -p >> var` even though `help local` suggests it should. > > How so? Do you mean that declare -p var in a function will show different > variables? See

Re: test -v for array does not work as documented

2020-02-23 Thread Chet Ramey
On 2/21/20 3:31 AM, pepa65 wrote: > On 21/02/2020 02.37, Chet Ramey wrote: >> It's unset because it doesn't have a value, but it retains the `local' >> attribute so it stays local if subsequently assigned one. > > Is there any reason the local attribute cannot be unset? If it would be > possible

Re: test -v for array does not work as documented

2020-02-21 Thread pepa65
On 21/02/2020 02.37, Chet Ramey wrote: > It's unset because it doesn't have a value, but it retains the `local' > attribute so it stays local if subsequently assigned one. Is there any reason the local attribute cannot be unset? If it would be possible then the "declare/typeset -p" would return 1

Re: test -v for array does not work as documented

2020-02-20 Thread Ulrich Mueller
> On Thu, 20 Feb 2020, Chet Ramey wrote: > On 2/20/20 10:05 AM, Ulrich Mueller wrote: >>> On Thu, 20 Feb 2020, pepa65 wrote: >> >>> On 20/02/2020 19.48, Ulrich Mueller wrote: Still, I think it's sad that there isn't a command that can test for assigned vs void variable, without

Re: test -v for array does not work as documented

2020-02-20 Thread Chet Ramey
On 2/20/20 10:05 AM, Ulrich Mueller wrote: >> On Thu, 20 Feb 2020, pepa65 wrote: > >> On 20/02/2020 19.48, Ulrich Mueller wrote: >>> Still, I think it's sad that there isn't a command that can test for >>> assigned vs void variable, without the need for parsing of declare -p >>> output. > >>

Re: test -v for array does not work as documented

2020-02-20 Thread Greg Wooledge
On Thu, Feb 20, 2020 at 04:05:01PM +0100, Ulrich Mueller wrote: > > On Thu, 20 Feb 2020, pepa65 wrote: > > > On 20/02/2020 19.48, Ulrich Mueller wrote: > >> Still, I think it's sad that there isn't a command that can test for > >> assigned vs void variable, without the need for parsing of

Re: test -v for array does not work as documented

2020-02-20 Thread Ulrich Mueller
> On Thu, 20 Feb 2020, pepa65 wrote: > On 20/02/2020 19.48, Ulrich Mueller wrote: >> Still, I think it's sad that there isn't a command that can test for >> assigned vs void variable, without the need for parsing of declare -p >> output. > There is no need to parse, the return value of

Re: test -v for array does not work as documented

2020-02-20 Thread pepa65
On 20/02/2020 19.48, Ulrich Mueller wrote: > Still, I think it's sad that there isn't a command that can test for > assigned vs void variable, without the need for parsing of declare -p > output. There is no need to parse, the return value of `declare -p var` or `typeset -p var` will tell you

Re: test -v for array does not work as documented

2020-02-20 Thread Ulrich Mueller
> On Wed, 19 Feb 2020, Stephane Chazelas wrote: > 2020-02-19 17:18:14 +0100, Ulrich Mueller: > [...] >> So, is there any syntax that allows to test if a value has been assigned >> to the array variable? Especially, to distinguish VARNAME=() (empty >> array) from VARNAME being unset? > [...]

Re: test -v for array does not work as documented

2020-02-19 Thread Grisha Levit
On Wed, Feb 19, 2020 at 11:38 AM Ulrich Mueller wrote: > Especially, to distinguish VARNAME=() (empty > array) from VARNAME being unset? I'm not sure if it's intended to work this way, but ${var@a} will report the attributes if the variable has any set, even if it does not have a value, like:

Re: test -v for array does not work as documented

2020-02-19 Thread Stephane Chazelas
2020-02-19 17:18:14 +0100, Ulrich Mueller: [...] > So, is there any syntax that allows to test if a value has been assigned > to the array variable? Especially, to distinguish VARNAME=() (empty > array) from VARNAME being unset? [...] You could do: if typeset -p var 2> /dev/null | grep -q '=';

Re: test -v for array does not work as documented

2020-02-19 Thread Chet Ramey
On 2/19/20 11:18 AM, Ulrich Mueller wrote: >> On Wed, 19 Feb 2020, Chet Ramey wrote: > >> On 2/19/20 7:00 AM, Ulrich Mueller wrote: >>> Bash Version: 5.0 >>> Patch Level: 16 >>> Release Status: release >>> >>> Description: >>> The GNU Bash Reference Manual Version 5.0 says about test -v: >>>

Re: test -v for array does not work as documented

2020-02-19 Thread pepa65
On 19/02/2020 23.18, Ulrich Mueller wrote: > So, is there any syntax that allows to test if a value has been assigned > to the array variable? Especially, to distinguish VARNAME=() (empty > array) from VARNAME being unset? Not `test` as such as we have just learned, but the returncode of `declare

Re: test -v for array does not work as documented

2020-02-19 Thread Ulrich Mueller
> On Wed, 19 Feb 2020, Chet Ramey wrote: > On 2/19/20 7:00 AM, Ulrich Mueller wrote: >> Bash Version: 5.0 >> Patch Level: 16 >> Release Status: release >> >> Description: >> The GNU Bash Reference Manual Version 5.0 says about test -v: >> '-v VARNAME' >> True if the shell variable VARNAME is

Re: test -v for array does not work as documented

2020-02-19 Thread Chet Ramey
On 2/19/20 7:00 AM, Ulrich Mueller wrote: > Bash Version: 5.0 > Patch Level: 16 > Release Status: release > > Description: > The GNU Bash Reference Manual Version 5.0 says about test -v: > '-v VARNAME' >True if the shell variable VARNAME is set (has been >

test -v for array does not work as documented

2020-02-19 Thread Ulrich Mueller
Configuration Information [Automatically generated, do not change]: Machine: x86_64 OS: linux-gnu Compiler: x86_64-pc-linux-gnu-gcc Compilation CFLAGS: -march=native -ggdb -O2 -pipe -Wno-parentheses -Wno-format-security uname output: Linux a1i15 4.19.102-gentoo #1 SMP Fri Feb 7 14:32:53 CET 2020