Bash における角括弧と二重括弧の違いは何ですか?

Bash における角括弧と二重括弧の違いは何ですか?

私は気づいたこの質問回答者の 1 人は二重括弧を使用し、もう 1 人は角括弧を使用していました。

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

...

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

二重括弧は見たことがありません。グーグルで検索してもわかりません。これらはまったく同じ意味ですか? 移植性に違いはありますか? どちらか一方を優先する理由はありますか?

答え1

マンページからbash:

   ((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.

数学的およびビット単位の比較を実行するには を使用し(( ))[[ ]]より抽象的な比較(test file attributes and perform string and arithmetic comparisons)を実行するには、例えば

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

関連情報