tiger-devel
[Top][All Lists]
Advanced

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

Re: [Tiger-devel] [RFC] Diferences between 'empty and set' and 'unset' v


From: Nicolas François
Subject: Re: [Tiger-devel] [RFC] Diferences between 'empty and set' and 'unset' variables
Date: Sat, 20 Sep 2003 20:53:50 +0200
User-agent: Mutt/1.5.4i

On Sat, Sep 20, 2003 at 05:59:57PM +0200, Javier Fernández-Sanguino Peña wrote:
> However, this does not work for me, scripts executing haveallvars do not
> run because of these changes. I have changed the code (and readded the val
> statement). Changes are in CVS, please take a look at them.

Thank you for all the time you passed on this. But if you think it's a
non issue (which is probably the case), don't loose your time on this.



I've tested the last CVS revision, but it did not worked as I expected:

=======================================================================
18:59:11$ cvs up -C initdefs
(Locally modified initdefs moved to .#initdefs.1.10)
U initdefs
18:59:24$ . initdefs
18:59:32$ a="1" ; haveallvars a ; echo $?
0
18:59:49$ a="" ; haveallvars a ; echo $?
--ERROR-- [init007e] Required variable a is empty.
1
18:59:54$ unset a ; haveallvars a ; echo $?
--ERROR-- [init007e] Required variable a is empty.
1
=======================================================================

I first thought that it was due to the colon: "${__var:?error}" tests
for a parameter that is unset or null; omitting the colon results in a
test only for a parameter that is unset.
But removing the colon didn't change anything. It seems that echo always
return true.

Using eval solved it:
__var is always set (it contains the name of the variable, "a" in my
tests), and thus ${__var?error} never reports any error.
By using eval: eval "echo \${$__var?error}", it really tests
if the variable is set (not if __var is set).
Here are the results of this version (a patch is attached):

=======================================================================
20:37:24$ . initdefs
20:39:35$ a="1" ; haveallvars a ; echo $?
0
20:39:44$ a="" ; haveallvars a ; echo $?
--ERROR-- [init007e] Required variable a is empty.
1
20:39:50$ unset a ; haveallvars a ; echo $?
--ERROR-- [init007e] Don't have required variable a.
1
=======================================================================
I hope it will be OK this time:)



I had also a look on the patch I posted yesterday. It seems to report
the right error, but __retval wasn't set to 1. adding '__retval=1' when
the variable is empty seems to correct it:

=======================================================================
19:11:55$ . initdefs
19:12:01$ a="1" ; haveallvars a ; echo $?
0
19:12:18$ a="" ; haveallvars a ; echo $?
--ERROR-- [init007e] Required variable a is empty.
1
19:12:22$ unset a ; haveallvars a ; echo $?
--ERROR-- [init007e] Don't have required variable a.
--ERROR-- [init007e] Required variable a is empty.
1
=======================================================================

hth
-- 
Nekral

Attachment: initdefs.diff
Description: Text document


reply via email to

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