if-then-elif-then-fi 구문을 반복적으로 길게 작성해야 하는 경우가 있다.
이 때, case 문을 사용할 수 있다.
case variable in
pattern1 | pattern2) command1;;
pattern3) command2;;
*) default command3;;
esac
ex) if-then-elif-then-else-fi
if [ $USER = "rich" ]; then
echo "Welcome $USER"
echo "Please enjoy your visit"
elif [ $USER = "barbara" ]; then
echo "Welcome $USER"
echo "Please enjoy your visit"
elif [ $USER = "testing" ]; then
echo "Special testing account"
elif [ $USER = "jessica" ]; then
echo "Do not forget to logout when your're done"
else
echo "Sorry, you are not allowed here"
fi
ex) case
case $USER in
rich | barbara )
echo "Welcome, $USER"
echo "Please enjoy your visit";;
testing)
echo "Special testing account";;
jessica)
echo "Do not forget to logout when you're done";;
*)
echo "Sorry, you are not allowed here";;
esac