test condition

Hi there,

I tried to search for this almost everywhere, but didnt get any proper information on it.

What is the difference between

[[  ]]

[ ]

Some of the code works when I have only single condition i.e.

[[ -z $arg1 ]] && $dothis1 || $dothis2

But if i try to include another testcondition to the above code like below

[[ -z $arg1 -a -n $arg2 ]] && $dothis1 || $dothis2

This works when I replace with single square brackets

[ -z $arg1 -a -n $arg2 ] && $dothis1 || $dothis2

Why is that so?

The shell keyword [[ requires a different syntax,
see below.

With bash:

$ type [[ 
[[ is a shell keyword
$ help [[
[[ ... ]]: [[ expression ]]
    Returns a status of 0 or 1 depending on the evaluation of the conditional
    expression EXPRESSION.  Expressions are composed of the same primaries used
    by the `test' builtin, and may be combined using the following operators
    
        ( EXPRESSION )  Returns the value of EXPRESSION
        ! EXPRESSION    True if EXPRESSION is false; else false
        EXPR1 && EXPR2  True if both EXPR1 and EXPR2 are true; else false
        EXPR1 || EXPR2  True if either EXPR1 or EXPR2 is true; else false
    
    When the `==' and `!=' operators are used, the string to the right of the
    operator is used as a pattern and pattern matching is performed.  The
    && and || operators do not evaluate EXPR2 if EXPR1 is sufficient to
    determine the expression's value.

So:

$ [ x = x -a x = x ] && echo ok
ok
$ [[ x = x -a x = x ]] && echo ok
bash: syntax error in conditional expression
bash: syntax error near `-a'

But:

$ [[ x == x && x == x ]] && echo ok
ok