Zsh Mailing List Archive
Messages sorted by:
Re: `[[ -n $VAR ]]` equal to `[[ $VAR ]]`?
- X-seq: zsh-users 20124
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Kurtis Rader <krader@xxxxxxxxxxxxx>
- Subject: Re: `[[ -n $VAR ]]` equal to `[[ $VAR ]]`?
- Date: Fri, 10 Apr 2015 04:46:58 +0200
- Cc: Thorsten Kampe <thorsten@xxxxxxxxxxxxxxxx>, Zsh Users <zsh-users@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=w4CEled5s8rWIlWs27JYsZBgz8WnoHjb0e+YrYtEEZQ=; b=OGryeXKbyI9bCBxXlLgLAmrX5iSfjgL6XqtDiw1LUaBkpRor9O9iLGutZhHr1w9WuJ QLBULpgeNtLGaRK01ltHqxDZz7Vd0gWUUeUEFNN/35qbfKCLo6VBMJ1lbcSN5Sd60agl 7EUMxNAEUMaqHmecz1FyWQrD/bnBOSRoKyHSQZDCw0wssWL607QYNJXKFAReMOohgrOD 0aJFcAHpaEGahAqMOToFWOCGeY35bzQfJnpaYwxqqB+UzNOxBC0dRBApx6q50okPVcJo OFocsSXtedxckMEPrfuxhQ29/OgpprXGyH0l/6ifC+yn//eQMcm1dHEQOLBJuXSWDbl+ k2OQ==
- In-reply-to: <CABx2=D93rJDoqGHa=9=nGZZU=9oC_vc-0FHE8ZERV9LmxtqRaA@mail.gmail.com>
- List-help: <mailto:firstname.lastname@example.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:email@example.com>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <firstname.lastname@example.org> <CABx2=D-VTpp3ihAE_A2KCdE3tcPu5RPuB8WJwtv-G=B0QNx0GQ@mail.gmail.com> <email@example.com> <CABx2=D9Mk01ovQkMyWT_1nh9WdDvcpqmMJAOdka-oEmN8Xe4nw@mail.gmail.com> <CABx2=D93rJDoqGHa=9=nGZZU=9oC_vc-0FHE8ZERV9LmxtqRaA@mail.gmail.com>
On Fri, Apr 10, 2015 at 4:05 AM, Kurtis Rader <krader@xxxxxxxxxxxxx> wrote:
> On Thu, Apr 9, 2015 at 7:02 PM, Kurtis Rader <krader@xxxxxxxxxxxxx> wrote:
>> On Thu, Apr 9, 2015 at 6:39 PM, Thorsten Kampe <thorsten@xxxxxxxxxxxxxxxx>
>>> if [[ $VAR ]]
>>> printf "something\n"
>>> printf "nothing\n"
>>> Works fine in zsh and bash.
>>> Same goes for
>>> `[[ $VAR ]] && printf "something\n" || printf "nothing\n"`
>> Okay, I had forgotten that a bare string is equivalent to "-n string" in
>> bash. The zsh documentation makes no mention of this "feature". It probably
>> works for you and not me because of an option that differs between our two
>> environments. Although for the life of me I can't figure out what that
>> option is.
> Bart's reply explains why I get a parse error: Mac OS X still has zsh
> v5.0.5 which does not support the bash semantics for a bare string inside
> [[ ]]. Even if you don't need compatibility with pre v5.0.6 zsh releases I
> would discourage that syntax because of its ambiguity.
(please don't top post, it's a lot of work to fix the mail before replying)
If you mean ambiguity because VAR might be the string "-z" for
example, there is no such ambiguity. The syntax of [[ ... ]] is fully
parsed before any substitutions inside are made (I think, but it's at
least true for this purpose). (This is unlike [ ... ] which is not
syntax but a shell builtin that gets passed arguments after they're
substituted, globbed, expanded and etc).
Messages sorted by: