Shell Programming--case judgment

Source: Internet
Author: User

Case Base Syntax:
Format case?? Variable name in
value1)
Command
;;
value2)
Command
;;
*)
Commond
;;
Esac
In a case program, you can use the |, meaning, or means of a condition, such as???
2|3)
Command
;;
Script

[[email protected] shell]# vim case.sh #!/bin/bashread -p "Please input a number: " nif [ -z "$n" ]then    echo "Please input a number."    exit 1fin1=`echo $n|sed ‘s/[0-9]//g‘`if [ -n "$n1" ]then echo "Please input a number." exit 1fiif [ $n -lt 60 ] && [ $n -ge 0 ]then    tag=1elif [ $n -ge 60 ] && [ $n -lt 80 ]then    tag=2elif [ $n -ge 80 ]  && [ $n -lt 90 ]then    tag=3elif [ $n -ge 90 ] && [ $n -le 100 ]then    tag=4else    tag=0ficase $tag in    1)        echo "不及格"        ;;    2)        echo "及格"        ;;    3)        echo "优秀"        ;;    4)        echo "非常优秀"        ;;    *)        echo "The number range is 0-100."        ;;esac

Execution results

[[email protected] shell]# sh case.shPlease input a number: 50不及格[[email protected] shell]# sh case.shPlease input a number: 60及格[[email protected] shell]# sh case.shPlease input a number: 80优秀[[email protected] shell]# sh case.shPlease input a number: 90非常优秀[[email protected] shell]# sh case.shPlease input a number: 116The number range is 0-100.[[email protected] shell]# sh case.shPlease input a number: aaaPlease input a number.

Shell Programming--case judgment

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.