in reply to Back-ticks and bash

G'day Wiggins,

"I searched for the program '[[', but none was found."

It's part of the shell syntax (see the bash manpage). It's used in conjunction with ']]'. Both are reserved words. Searching in the manpage finds, among others:

RESERVED WORDS ... The following words are recognized as reserved ... [[ + ]]

and, later

SHELL GRAMMAR ... [[ expression ]] ... the evaluation of the conditional expression expr +ession. ... ...

— Ken

Replies are listed 'Best First'.
Re^2: Back-ticks and bash
by Wiggins (Hermit) on Oct 09, 2016 at 13:29 UTC
    What I remenbered was /usr/bin/[ which is an external program used for doing tests I believe, and that is still there. I always find bash syntax confusing and obscure.

    It is always better to have seen your target for yourself, rather than depend upon someone else's description.

      [ in bash is a synomym for test but it's not still a builtin. For backward compatibility, it behaves similarly to /usr/bin/[ , which means variables among its arguments are still expanded by the shell, which is not true for [[ . In other words, you have to write things like
      if [ "$x" = abc ]

      i.e. you need to quote the variables, while with `[[` you don't have to, as the shell processes the parameters before expansion:

      if [[ $x = abc ]]

      Also, `[[` introduces pattern matching [[ $x = ab* ]] and `=~` you might now from Perl.

      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,