shell中的逻辑判断while

 

w|head -1|awk -F'load average: ' '{print $2}'|cut -d. -f1

 

#!/bin/bash

while true
do
load=`w|head -1|awk -F'load average: ' '{print $2}'|cut -d. -f1`
if [ $load -gt 10 ]
then
echo $load
fi
sleep 30
done

 

  

#!/bin/bash
while true
do
    read -p "Please input a number:" n

    if [ -z "$n" ]
    then
        echo "you need input sth"
        continue
     fi

     n1=`echo $n|sed 's/[0-9]//g'`
     if [ -n "$n1" ]
     then
        echo "you just only input numbers"
        continue
     fi

      break
done
echo $n

  

 

posted @ 2018-03-14 14:58  你好!2022  阅读(725)  评论(0编辑  收藏  举报