I understand the OP considering that clumsy. And something being defined
by POSIX doesn't prevent it being clumsy or not defined in an optimal way;
sometimes even the opposite is true. But I'd rather like to abstain from such
flame-prone valuations and consider the given application.
@Axel: I'm not sure your sample is only test code. If so, you can trigger the
effecte more simply (without if condition) by /bin/ksh -uc 'echo ${TESTVAR}'.
Otherwise I'd use the less clumsy /bin/ksh -uc 'echo ${TESTVAR-"undefined"}
(without if, but still with the default value substitution).
Part of the clumsiness in your sample stems from the explicit if test and the
implicit test in ${v- }; one can be avoided.Janis > Date: Wed, 16 Oct 2013 14:23:57 +0200 > From: [email protected] > To: [email protected] > CC: [email protected] > Subject: Re: [ast-users] Question about the nounset option > > On 16 October 2013 09:14, PHILIPP, Axel, Dr. <[email protected]> wrote: > > I wonder whether it is desirable that test -n and test -z trigger the unset > > error condition: > > > > /bin/ksh -uc 'if [[ -n $TESTVAR ]]; then echo $TESTVAR; else echo > > "undefined"; fi' > > /bin/ksh: TESTVAR: parameter not set > > > > I know all shells from the sh family I have tested behave this way, but I > > would prefer a solution (additional option or env var) that the error is > > not triggered in these test cases. > > You can use [[ -v TESTVAR ]] to test whether a variable does exists or > not. This uses the variables name (TESTVAR) and not the value > ($TESTVAR). > > > > > The obvious workaround is somewhat clumsy: > > /bin/ksh -uc 'if [[ -n ${TESTVAR-} ]]; then echo $TESTVAR; else echo > > "undefined"; fi' > > undefined > > Why is this clumsy? This is how POSIX sh was designed and everyone > uses as designed. Why is this a problem? > > Lionel > _______________________________________________ > ast-users mailing list > [email protected] > http://lists.research.att.com/mailman/listinfo/ast-users
_______________________________________________ ast-users mailing list [email protected] http://lists.research.att.com/mailman/listinfo/ast-users
