zsh-users
 help / color / mirror / code / Atom feed
* [[ ... ]], [ ... ], bash, zsh
@ 2003-08-13 22:16 Haakon Riiser
  2003-08-13 22:44 ` Björn Lindström
  0 siblings, 1 reply; 4+ messages in thread
From: Haakon Riiser @ 2003-08-13 22:16 UTC (permalink / raw)
  To: zsh-users

In both bash and zsh, the "-n" operator in [ ... ] is optional,
but in [[ ... ]] it's only optional in bash.  Is there a reason
for this?

Thanks in advance for any response!

-- 
 Haakon


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [[ ... ]], [ ... ], bash, zsh
  2003-08-13 22:16 [[ ... ]], [ ... ], bash, zsh Haakon Riiser
@ 2003-08-13 22:44 ` Björn Lindström
  2003-08-13 23:08   ` Haakon Riiser
  0 siblings, 1 reply; 4+ messages in thread
From: Björn Lindström @ 2003-08-13 22:44 UTC (permalink / raw)
  To: zsh-users

Haakon Riiser <haakon.riiser@fys.uio.no> writes:

> In both bash and zsh, the "-n" operator in [ ... ] is optional, but in
> [[ ... ]] it's only optional in bash.  Is there a reason for this?

If you use [ ], the test is supposed to work like with test(1). In the
case of zsh this is still handled by a built-in, I don't know how it is
with bash. The [[ syntax is a shell-specific extension, and there are
several differences between the shells on how the are interpreted.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [[ ... ]], [ ... ], bash, zsh
  2003-08-13 22:44 ` Björn Lindström
@ 2003-08-13 23:08   ` Haakon Riiser
  2003-08-14  1:29     ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Haakon Riiser @ 2003-08-13 23:08 UTC (permalink / raw)
  To: zsh-users

[Björn Lindström]

>> In both bash and zsh, the "-n" operator in [ ... ] is optional, but in
>> [[ ... ]] it's only optional in bash.  Is there a reason for this?

> If you use [ ], the test is supposed to work like with test(1). In the
> case of zsh this is still handled by a built-in, I don't know how it is
> with bash. The [[ syntax is a shell-specific extension, and there are
> several differences between the shells on how the are interpreted.

Okay, I thought the [[ ... ]] command was mentioned in POSIX.
Still, it seems strange that [[ ... ]] and [ ... ] would differ
with regard to the -n operator;

  if [[ $INITIALIZED ]]; then
      ...
  fi

reads better than

  if [[ -n $INITIALIZED ]]; then
      ...
  fi

so I just wanted to know why it was decided that -n should not
be optional.  (No, it's not important, but I'd feel better if I
knew the reason. :-)

-- 
 Haakon


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [[ ... ]], [ ... ], bash, zsh
  2003-08-13 23:08   ` Haakon Riiser
@ 2003-08-14  1:29     ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2003-08-14  1:29 UTC (permalink / raw)
  To: zsh-users

On Aug 14,  1:08am, Haakon Riiser wrote:
} Subject: Re: [[ ... ]], [ ... ], bash, zsh
}
}   if [[ $INITIALIZED ]]; then
} 
}   if [[ -n $INITIALIZED ]]; then
} 
} so I just wanted to know why it was decided that -n should not
} be optional.

It's not the case that someone decided that -n should not be optional.

It is the case that someone decided that arbitrary non-empty strings
should not be considered equivalent to the value "true", and that the
empty string should not be considered equivalent to "false".

The zsh [[ ]] is based on ksh, not on bash:

$ [[ $INITIALIZED ]]
ksh: syntax error: `$INITIALIZED' missing expression operator

So "someone" is probably David Korn.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-08-14  1:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-13 22:16 [[ ... ]], [ ... ], bash, zsh Haakon Riiser
2003-08-13 22:44 ` Björn Lindström
2003-08-13 23:08   ` Haakon Riiser
2003-08-14  1:29     ` Bart Schaefer

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).