shell脚本 if判断switch分支

if [[ "$sel" -lt 1 || "$sel" -gt 5 ]]
then 
  echo "Error input! Please input again:"
else
  break
fi

语法

if(空格  表达式  空格)#如果没有空格报then未识别错误(格式错误)

then 

  条件满足语句

else

  不满足语句

fi 结束语句

 

gt-大于

lt-小于

case "$sel" in
	  		1) date;;
	 		2) who;;
	  		3) pwd;;
	  		4) ls;;
	  		5) exit;;
	 		*) echo -e "There is no selection $select\n";;
		esac 

case 变量 in

  1)变量匹配结果1的操作 date ; ;

  *)其他情况操作 exit 

esac 语句结束

 

posted @ 2021-10-14 11:19  困到很想醒  阅读(271)  评论(0编辑  收藏  举报