On 10/25/16 12:40 AM, Martijn Dekker wrote:
> Op 25-10-16 om 00:42 schreef Stuart Shelton:
>> Failing this, is there any alternative to ‘typeset’ to list a
>> variable declared as local to a function but which has not yet been
>> assigned a value?
> 
> Try simply testing the exit status of 'typeset -p' or 'declare -p'. If
> the variable is not declared, it exits unsuccessfully.
> 
>     if typeset -p "$var" >/dev/null 2>&1 && [[ ! -v $var ]]
>     then ...
> 
> As far as I can tell, this is not documented in 'help' or in the info
> page, by the way. Perhaps it should be.

It's documented.  The man page, for instance, says:

"The return value is 0 unless ... one of the names is not a valid shell
variable name"

which handles both the "not correctly formed" and "not found" cases.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    c...@case.edu    http://cnswww.cns.cwru.edu/~chet/

Reply via email to