$ 없이 변수 확장이 표현식에서 작동하는 이유는 무엇입니까?

$ 없이 변수 확장이 표현식에서 작동하는 이유는 무엇입니까?
#!/bin/bash

VALUE=10

if [[ VALUE -eq 10 ]]
then
    echo "Yes"
fi

놀랍게도 "예"가 출력됩니다. 나는 그것이 필요하다고 생각했습니다 . 섹션을 [[ $VALUE -eq 10 ]]조사했지만 이 동작을 설명할 수 있는 항목을 찾지 못했습니다.CONDITIONAL EXPRESSIONSman bash

답변1

[[bash 예약어이므로 와 같은 산술 이진 연산자를 사용하는 대신 산술 확장과 같은 특수 확장 규칙이 적용됩니다 [. -eq따라서 쉘은 정수 표현식을 찾고 첫 번째 항목에서 텍스트를 찾으면 이를 인수로 확장하려고 시도합니다. 산술 확장이라고 하며 에 존재합니다 man bash.

RESERVED WORDS
       Reserved words are words that have a special meaning to the shell.  
       The following words are recognized as reserved 
       [[ ]]

[[ 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 substitution, and 
       quote removal are performed.  

Arithmetic Expansion
       The evaluation is performed according to the rules listed below 
       under ARITHMETIC EVALUATION.

ARITHMETIC EVALUATION
       Within an expression, shell variables may also be referenced 
       by name without using the parameter expansion syntax.

예를 들어:

[[ hdjakshdka -eq fkshdfwuefy ]]

항상 true를 반환합니다

하지만 이렇게 하면 오류가 반환됩니다.

$ [[ 1235hsdkjfh -eq 81749hfjsdkhf ]]
-bash: [[: 1235hsdkjfh: value too great for base (error token is "1235hsdkjfh")

재귀를 사용할 수도 있습니다.

$ VALUE=VALUE ; [[ VALUE -eq 12 ]]
-bash: [[: VALUE: expression recursion level exceeded (error token is "VALUE")

관련 정보