본문 바로가기

Programming Practice/Shell & Server Management

조건문

1. 조건문

1) if 로 시작해서 fi로 끝남

2) java에서 else if 는 shell 에서 elif 로 설정

3) 기본적인 조건과 그에 따른 명령은 아래와 같이 설정함

if [ 조건1 ]; then

명령1;

elif [ 조건2 ]; then

명령2;

else

명령3;

fi 

ex)


4) 조건을 2개 모두 만족시켜야 하는 경우,

[조건1] && [조건2]; then

ex)

조건을 2개 중 1개만 만족시켜도 되는 경우,

[조건1] || [조건2]; then

5) 등호/부동호 사용

<문자>

 조건

형식 

 같음

Str1 = Str2 

 다름

Str1 != Str2 

 null이 아님

-n Str1 

 null임

-z Str1 

<숫자>

 조건

형식 

 같음

expr1 -eq expr2

 다름

expr1 -ne expr2 

 큼

expr1 -gt expr2

 크거나 같음

expr1 -ge expr2 

 작음

expr1 -lt expr2 

 작거나 같음

expr1 -le expr2