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