From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10020 invoked by alias); 10 Apr 2015 02:47:04 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 20124 Received: (qmail 16959 invoked from network); 10 Apr 2015 02:47:00 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 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== MIME-Version: 1.0 X-Received: by 10.50.111.168 with SMTP id ij8mr811865igb.43.1428634018866; Thu, 09 Apr 2015 19:46:58 -0700 (PDT) In-Reply-To: References: Date: Fri, 10 Apr 2015 04:46:58 +0200 Message-ID: Subject: Re: `[[ -n $VAR ]]` equal to `[[ $VAR ]]`? From: Mikael Magnusson To: Kurtis Rader Cc: Thorsten Kampe , Zsh Users Content-Type: text/plain; charset=UTF-8 On Fri, Apr 10, 2015 at 4:05 AM, Kurtis Rader wrote: > On Thu, Apr 9, 2015 at 7:02 PM, Kurtis Rader wrote: >> On Thu, Apr 9, 2015 at 6:39 PM, Thorsten Kampe >> wrote: >> >>> >>> ``` >>> VAR= >>> >>> if [[ $VAR ]] >>> then >>> printf "something\n" >>> else >>> printf "nothing\n" >>> fi >>> ``` >>> >>> 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). -- Mikael Magnusson