shell脚本中的逻辑判断 文件目录属性判断 if特殊用法 case判断

shell脚本中的逻辑判断 文件目录属性判断 if特殊用法 case判断

shell脚本中的逻辑判断 文件目录属性判断 if特殊用法 case判断

shell脚本中的逻辑判断 文件目录属性判断 if特殊用法 case判断

shell脚本中的逻辑判断 文件目录属性判断 if特殊用法 case判断

shell脚本中的逻辑判断 文件目录属性判断 if特殊用法 case判断

shell脚本中的逻辑判断 文件目录属性判断 if特殊用法 case判断

shell脚本中的逻辑判断 文件目录属性判断 if特殊用法 case判断

case判断

• 格式 case  变量名 in 
                     value1)
                          command
                          ;;
                     value2)
                          command
                          ;;
                      *)
                        commond
                            ;;
                      esac
• 在case程序中,可以在条件中使用|,表示或的意思, 比如    
2|3) 
    command
    ;;


shell脚本案例

 #!/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

讲解
输入一个数字  read -p   "please input a  number" n
-ge (greater equeal大于等于)
-le (less than equal小于等于)

 

相关文章:

  • 2022-12-23
  • 2022-01-04
  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
  • 2021-10-08
  • 2022-12-23
猜你喜欢
  • 2021-08-07
  • 2021-09-11
  • 2021-11-19
  • 2021-04-24
  • 2021-07-08
  • 2021-07-22
相关资源
相似解决方案