Bash에서 대괄호와 이중 괄호의 차이점은 무엇입니까?

Bash에서 대괄호와 이중 괄호의 차이점은 무엇입니까?

나는 알아차렸다이 질문한 응답자는 이중 괄호를 사용했고 다른 응답자는 대괄호를 사용했습니다.

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

관련 정보