Search

If

비교 연산자
[ -n num1 ] # num1의 문자열 길이가 0 이 아니면 true [ -z num1 ] # num1의 문자열 길이가 0 이면 true [ num1 -eq num2 ] # num1 == num2 [ num1 -ne num2 ] # num1 != num2 [ num1 -gt num2 ] # num1 > num2 (greater than) [ num1 -ge num2 ] # num1 >= num2 [ num1 -lt num2 ] # num1 < num2 (less than) [ num1 -le num2 ] # num1 <= num2
Shell
복사
변수 값이 3과 같을 때 실행된다.
if [ $VARIABLE1 -eq 3 ]; then # hi fi
Shell
복사
$VARIABLE1이 문자열 "3"과 같다면 실행된다.
if [[ $VARIABLE1 == 3 ]]; then # hi fi
Shell
복사
cat hi 명령어가 성공적(exit code 0)으로 처리되면 실행된다.
if cat hi; then # cat successfully fi
Shell
복사