bug-bash
[Top][All Lists]
Advanced

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

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


From: Stephane Chazelas
Subject: Re: test -v for array does not work as documented
Date: Wed, 19 Feb 2020 16:55:50 +0000
User-agent: NeoMutt/20180716

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 '='; then
  echo var has a value
fi

For namerefs, that's whether they are referencing a variable,
that variable could still be undeclared (let alone set).

-- 
Stephane



reply via email to

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