Anonymous 发表于 2019-10-8 20:09:16

课程第33次

sub_answer() {
      unset SUBANS
      
      sub_sub_answer(){
                SUBANS=`echo $SUBANS |tr -d "[:blank:]"`
                if [ -z $SUBANS ]
                then
                SUBANS="NULL"
                fi
      }
      
      read -p "$1" SUBANS
      sub_sub_answer
      
      until [ $SUBANS =="y"-o$SUBANS =="n" ]
      do
                echo "This question should be answered either with \"y\"or \"n\"."
                read -p "$1" SUBANS
                sub_sub_answer
      done
      
}






sub_confirm() {
      unset SUBCON1
      unset SUBCON2
      SUBCON1=0
      SUBCON2=1
      until [ $SUBCON1 == $SUBCON2 ]
      do
                read -p "$1" SUBCON1
                sub_answer "Input is: \"$SUBCON1\". Are you sure ?(y/n)"
                if [ -z $SUBCON1 ]
                then
               SUBCON1="NULL"
                fi
                if [ $SUBANS == "y" ]
                then
                SUBCON2=$SUBCON1
                fi
      done
}




sub_red() {
echo -e "\033[31;1m${1}\033[0m"
}      


sub_green() {
echo -e "\033[32;1m${1}\033[0m"
}

sub_red_blink() {
echo -e "\033[31;5;1m${1}\033[0m"
}


sub_green_blink() {
echo -e "\033[32;5;1m${1}\033[0m"
}


sub_ping() {
rm -f /tmp/sub_ping.txt
for i in {1..254}
do
(ifping -c 8 -W 1 -q $SUBCON1.$i > /dev/null 2>&1
then
   echo 192.168.0.$i is online
fi )>> /tmp/sub_ping.txt &
done
wait
sort -t . -k 4 -n /tmp/sub_ping.txt
}




#!/bin/sh


../10.lib

sub_confirm "Pls input IP NET ADDRESS:"

sub_red"Your input is$SUBCON1"
sub_green"Your input is$SUBCON1"
sub_red_blink"Your input is$SUBCON1"
sub_green_blink"Your input is$SUBCON1"

sub_pingRH124: 上完1 2 3 4 5 6 7 8 9 101112 131415 16
RH134: 上完 1 2 3 4 5 6 78 9 10 11 12 13 14 15
RH254: 上完 1 2 3 4 5 6 7 891011 12 13 1415
#!/bin/sh

read -p "Pls input color :"v_color
read -p "Pls input shape :"v_shape

case ${v_color}${v_shape} in
rr)
echo red-round
;;
gr)
echo green-round
;;
*)
echo other
;;
esac两个条件“或”判断:
read -p "pls input num1: " v_num1
read -p "pls input num2: " v_num2

if [ $v_num1 -lt 10 -o $v_num2 -lt 10 ]
then
echo OK
fi可以改写成:
read -p "pls input num1: " v_num1
read -p "pls input num2: " v_num2

if [ $v_num1 -lt 10 ] || [ $v_num2 -lt 10 ]
then
echo OK
fi#!/bin/sh

read -p "Pls input color :"v_color
read -p "Pls input shape :"v_shape

case ${v_color}${v_shape} in
rr|rt)
echo red-round or red-triangle
;;
gr)
echo green-round
;;
*)
echo other
;;
esac



页: [1]
查看完整版本: 课程第33次