Linux中退出循环命令

[root@a ~]#cat break.sh

#!/bin/bash

while :      #其中“:”表示while循环的条件永远为真的意思

do

  read -p "Enter a number [1-5]: "  num

  case $num in

      1|2|3|4|5)

        echo "It's OK"

         ;;

       *)

          echo "Wrong,bye-bye!"

          break

  esac

done

[root@a ~]#sh break.sh

Enter a number [1-5]: 3

It's OK

Enter a number [1-5]: 5

It's OK

Enter a number [1-5]:24

Wrong,bye-bye

猜你喜欢

转载自www.cnblogs.com/xiaofeng666/p/10858195.html
今日推荐