shell 中条件判断
if “条件”; then
elif "条件"; then
else
fi
then 如果和条件放在同一行,则条件和 then 之间需要用分号分割,如果不在一行,则不需要用分号分割
#!/bin/sh
echo "Are you a teacher, please answer yes or no"
read param
if [ "$param" = "yes"]; then
echo "I am a teacher"
esif [ "$param" = "no" ];
then
echo "I am not a teacher"
else
echo "Sorry, $param not recognize. Enter
yes or no"
fi
exit 0
实例中 read 读取用户输入,并将值赋值给 param。
判断中去参数 param 外边加引号的目的是防止用户不输入任何内容,直接回车