[Top][All Lists]

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

Re: Race in bash-4.3 'typeset'?

From: Martijn Dekker
Subject: Re: Race in bash-4.3 'typeset'?
Date: Fri, 28 Oct 2016 17:31:28 +0100
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.4.0

Op 28-10-16 om 15:00 schreef Chet Ramey:
> On 10/25/16 12:40 AM, Martijn Dekker wrote:
>> 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.

To me that seems like a far-fetched interpretation. The way I read it,
if a variable is not declared, that does not imply its name is not
valid. An invalid name would mean it is impossible to declare it. I
think adding ", the variable is not declared" would prevent

- M.

reply via email to

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