bug-bash
[Top][All Lists]
Advanced

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

Re: Race in bash-4.3 'typeset'?


From: L. A. Walsh
Subject: Re: Race in bash-4.3 'typeset'?
Date: Tue, 25 Oct 2016 12:45:26 -0700
User-agent: Thunderbird



Stuart Shelton wrote:
I have some code which evals a configuration file - but before doing so 
attempts to validate the content.  It does this by taking each potential 
keyword from the file and then doing:

if typeset -p | grep -q "^declare -. ${var}$”; then

… to determine whether the keyword in question exists as a declared but unset 
variable in the script.
---
   I don't think you can do that, primarily because
you can't see the fact that something is declared but unset.
"typeset -p" displays "attributes" AND "values".  If the variables has
no value, then how would it display that?

   Also, in the above, what if the variable is declared as an
integer and exported?  Your grep-expression won't match, as
it only allows for 1 flag.  You might want to use grep -Pq and
put a "+" after the "-."
Also, what is ${var} supposed to contain?  I'm guessing that var
isn't your variable you are testing for but maybe the name of the
var?
I've had that confusion in some scripts where I had functions taking
arrays of 'var' -- which for some meant arrays of values, but in
other cases I needed the names of the vars that contained those values.
I ended up with a weak rule to try to always append "nam[e]" or "str[ing]"
to things that were to be interpreted as names or strings, then
using nothing, or 'ptr' or 'ref' on the end to indicate it was
a reference to the value, like:

var=33
varname=var
echo "name of var=$varname, value=$var"

Anyway, even if you fixed the regex, I think you'll have problems
trying to detect unset variables...


problems due to my 1st paragraph, above

However, I am seeing cases where the above incorrectly fails, or where executing this line twice in immediate succession will fail on the first invocation and then succeed on the second.
----
   Is it being assigned a value between invokations?


-l




reply via email to

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