* Re: `[[ -n $VAR ]]` equal to `[[ $VAR ]]`?
[not found] ` <CABx2=D_4Aw4W9AsBNa5o1houzAipLFDBtt82BnVq0CEyNshSUA__23909.3113611036$1428636185$gmane$org@mail.gmail.com>
@ 2015-04-10 20:33 ` Stephane Chazelas
0 siblings, 0 replies; only message in thread
From: Stephane Chazelas @ 2015-04-10 20:33 UTC (permalink / raw)
To: zsh-workers
2015-04-09 20:21:50 -0700, Kurtis Rader:
[...]
> if [ "${var}x" = x ]; then
>
> so that if $var was unset or the empty string you still had a valid
> expression.
[...]
No, that "x" (and you need it *before* $var) was never about empty $var,
if [ "$var" = "" ]
is perfectly fine in the Bourne shell when $var is empty.
The problem is with values of $var like ! or (.
That's for those that you need:
if [ "x$var" = x ]
or
if [ "" = "$var" ]
IIRC
if [ -n "$var" ]
would be a problem for values of $var like = in some shell.
Still is with /bin/sh on Solaris 10.
I don't know if any shell ever had a problem with
if [ "${var}x" = x ]
when $var == "-". I wouldn't bet on it.
Now POSIX clearly specifies "[" aka test when the number of
arguments is less than 4, so one can count on
[ -n "$var" ]
and
[ "$var" = "" ]
being reliable in conformant shells/tests.
More info at:
http://www.in-ulm.de/~mascheck/various/test/
--
Stephane
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2015-04-10 20:37 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <mg78mg$vqb$1@ger.gmane.org>
[not found] ` <CABx2=D-VTpp3ihAE_A2KCdE3tcPu5RPuB8WJwtv-G=B0QNx0GQ@mail.gmail.com>
[not found] ` <mg79kr$vqb$2@ger.gmane.org>
[not found] ` <CABx2=D9Mk01ovQkMyWT_1nh9WdDvcpqmMJAOdka-oEmN8Xe4nw@mail.gmail.com>
[not found] ` <CABx2=D93rJDoqGHa=9=nGZZU=9oC_vc-0FHE8ZERV9LmxtqRaA@mail.gmail.com>
[not found] ` <CAHYJk3Qj6W=VZ26si0VjhsmS1u9go6mVGpXjDSTLk5knKaEtOg@mail.gmail.com>
[not found] ` <CABx2=D_4Aw4W9AsBNa5o1houzAipLFDBtt82BnVq0CEyNshSUA__23909.3113611036$1428636185$gmane$org@mail.gmail.com>
2015-04-10 20:33 ` `[[ -n $VAR ]]` equal to `[[ $VAR ]]`? Stephane Chazelas
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).