0

This question already has an answer here:

I notice in this question that one answerer used double parentheses where the other used square brackets:

if (( $(fileSize FILE1.txt) != $(fileSize FILE2.txt) )); then

...

if [ $(fileSize FILE1.txt) != $(fileSize FILE2.txt) ]; then

I haven't seen double parentheses before - and googling doesn't help. Do they have exactly the same meaning? Any difference in portability? Reason to prefer one over the other?

marked as duplicate by don_crissti, Gilles bash Apr 10 '17 at 23:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

From the bash manpage:

   ((expression))
          The  expression is evaluated according to the rules described below under ARITHMETIC EVALUATION.  If the value of the expression is
          non-zero, the return status is 0; otherwise the return status is 1.  This is exactly equivalent to let "expression".

   [[ expression ]]
          Return a status of 0 or 1 depending on the evaluation of the conditional expression expression.  Expressions are  composed  of  the
          primaries  described  below  under  CONDITIONAL  EXPRESSIONS.  Word splitting and pathname expansion are not performed on the words
          between the [[ and ]]; tilde expansion, parameter and variable expansion, arithmetic expansion, command substitution, process  sub‐
          stitution, and quote removal are performed.  Conditional operators such as -f must be unquoted to be recognized as primaries.

You use (( )) to perform mathematic and bitwise comparison, and [[ ]] to perform more abstract comparisons (to test file attributes and perform string and arithmetic comparisons), for example

touch test;
if [ -e test ]; then
    echo test exists
else
    echo test does not exist
fi

Not the answer you're looking for? Browse other questions tagged or ask your own question.