From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25749 invoked by alias); 10 Apr 2015 03:21:55 -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: 20126 Received: (qmail 28859 invoked from network); 10 Apr 2015 03:21:54 -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.6 required=5.0 tests=BAYES_00,HTML_MESSAGE, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=ttWpIJVKtsrz+UANH/WuTEMz6lTihNwWppLUXLbFkNA=; b=MdJRR9hQ4XtpUFN/mNxzGU+f5PL1I/cd1YO7niudxaH+YRgu4Mw3utrr0r4KF3CAWi 5aKD9376/1+U/5nI+pIdZQapKDgDwuN4w1EuFJ9AtclPU9s2Fq5A4UQKq/3Yf1DfGHbF 4OZdpxiaxSZcFvB6mjSmvIXxC4cBiBpPn5n0iLbBDFyMYhoxkfmAv+3NfXky288zeU4L Tr/D6umOquGPv46WmAr/ZbDEz61I1D4P3lUR55FP0sy4xxket9SrDgtFdFUkakZYKFti zC15eqcXgs3f+G10Zg7u/LeJJniCCl7yrx1Wl0TLYDcOgLa/pZLRDhSlC/qYQCLF/uQl iY/w== X-Gm-Message-State: ALoCoQnd6TvLvd3dGRstcBlD8YeY33izQ15KZTxSciOb2ILLDVbnac9iJvO88P2k8+ubpayJyiK1 MIME-Version: 1.0 X-Received: by 10.152.87.162 with SMTP id az2mr7236517lab.58.1428636110718; Thu, 09 Apr 2015 20:21:50 -0700 (PDT) In-Reply-To: References: Date: Thu, 9 Apr 2015 20:21:50 -0700 Message-ID: Subject: Re: `[[ -n $VAR ]]` equal to `[[ $VAR ]]`? From: Kurtis Rader To: Mikael Magnusson Cc: Thorsten Kampe , Zsh Users Content-Type: multipart/alternative; boundary=001a11c33f28e4a1370513564371 --001a11c33f28e4a1370513564371 Content-Type: text/plain; charset=UTF-8 On Thu, Apr 9, 2015 at 7:46 PM, Mikael Magnusson wrote: > 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). > Your last statement is only partially true. It is true that most modern shells implement the single bracket form as a builtin (the double bracket form has always been a builtin in ksh, zsh, etc.). However, historically the "[" command was simply an alias (usually a file system hard-link) for /bin/test. The original Bourne shell simply executed that external command and checked its exit status. Check your /bin or /usr/bin directory and you'll likely see a file named "[" (although it may not be a link to /bin/test these days). The fact the "[" was historically an external command is why you have to jump through hoops to quote variable expansions and use tricks like if [ "${var}x" = x ]; then so that if $var was unset or the empty string you still had a valid expression. -- Kurtis Rader Caretaker of the exceptional canines Junior and Hank --001a11c33f28e4a1370513564371--