Logic judgment in shell script file directory attribute judgment if special usage case judgment

 

 

 

case judgment

• Format case   variable name in 
                     value1)
                          command
                          ;;
                     value2)
                          command
                          ;;
                      *)
                        commond
                            ;;
                      esac 
• In a case program, you can use | in a condition to mean or, such as    
 2 | 3 
    command
    ;;


shell script case

 #!/bin/bash
read -p "Please input a number: " n    
if [ -z "$n" ]
then
    echo "Please input a number."
    exit 1
fi
n1=`echo $n|sed 's/[0-9]//g'`
if [ -n "$n1" ]
then
 echo "Please input a number."
 exit 1
fi
if [ $n -lt 60 ] &&[ $n -ge 0 ]
then
    tag=1
elif [ $n -ge 60 ] && [ $n -lt 80 ]
then
    tag=2
elif [ $n -ge 80 ]  && [ $n -lt 90 ]
then
    tag=3
elif [ $n -ge 90 ] && [ $n -le 100 ]
then
    tag=4
else 
    tag=0
fi

case $tag in
    1)
    echo "not ok"
        ;;
    2)
        echo "ok"
        ;;
    3)
        echo "ook"
        ;;
    4)
        echo "oook"
        ;;
    *)
        echo "The number range is 0-100."
        ;;
esac

explain
Enter a number read -p    " please input a number " n
 - ge (greater equeal greater than or equal to)
 -le ( less than equal less than or equal to)

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324670146&siteId=291194637