Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [[ ... ]], [ ... ], bash, zsh



[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



Messages sorted by: Reverse Date, Date, Thread, Author