[vim을 이용한 5를 제외한 구구단 2단 출력 ]
[rapa@localhost test_folder]$ mkdir work_sh
[rapa@localhost test_folder]$ cd work_sh/
[rapa@localhost work_sh]$ vim gugudan_2.sh
#!/bin/sh
numb=2
for (( i=1; i<10; i++ ))
do
result=$(expr $numb \\* $i)
if [ $i != 5 ]
then
echo $numb"x"$i=$result
fi
done
ELSE문
[코드를 더 직관적으로 바꿔보기(else 사용)]
#!/bin/sh
numb=2
for (( i=1; i<10; i++ ))
do
result=$(expr $numb \\* $i)
if [ $i == 5 ]
then
continue
else
echo $numb"x"$i=$result
fi
done
ELIF문
[elif 문 예시]
[rapa@localhost work_sh]$ vim test_if_elif.sh
#!/bin/sh
keyword=pipeline
if [ $keyword == modelling ]
then
echo 모델링 팀이네요
elif [ $keyword == pipeline ]
then
echo 파이프라인 팀이시군요! 너무 멋져요
else
echo 뭐라구요?
fi
결과값
[rapa@localhost work_sh]$ sh test_if_elif.sh 1
파이프라인 팀이시군요! 너무 멋져요
[변수에 팀 이름을 넣어 작동시키기]
#!/bin/sh
keyword=$1
if [ $keyword == modelling ]
then
echo 모델링 팀이네요
elif [ $keyword == pipeline ]
then
echo 파이프라인 팀이시군요! 너무 멋져요
else
echo 뭐라구요?
fi