熬死你的 发表于 2018-8-22 12:02:58

第14章练习,shell脚本编程实例-1

### level=1  
i=1
  
while [ $i -le 4 ];do
  
      j=1;k=1
  
      while [ $j -le 4 ];do
  
                echo -e "\033[49m\033[0m\033[47m\033[0m\c"
  
                let j++
  
      done
  
      echo
  
      while [ $k -le 4 ];do
  
                echo -e "\033[47m\033[0m\033[49m\033[0m\c"
  
                let k++
  
      done
  
      echo
  
      let i++
  
done
  
###
  
echo
  
echo this is level 1
  
echo
  
echo
  
#### level=2
  
#
  
declare -i s
  
while true;do
  
      read -p "choose the level 1-9: " s
  
                if [[ "$s" =~ ^$ ]] &>/dev/null ;then
  
                        break
  
                else
  
                        echo wrong number
  
                fi
  
done
  

  
PS3="choose the first color(1-8): "
  
select manu in red green yellow blue voilet light-blue white black;do
  
      case $manu in
  
      red)
  
                echo you have choose the $manu be the first color
  
                break
  
                ;;
  
      green)
  
                echo you have choose the $manu be the first color
  
                break
  
                ;;
  
      yellow)
  
                echo you have choose the $manu be the first color
  
                break
  
                ;;
  
      blue)
  
                echo you have choose the $manu be the first color
  
                break
  
                ;;
  
      voilet)
  
                echo you have choose the $manu be the first color
  
                break
  
                ;;
  
      light-blue)
  
                echo you have choose the $manu be the first color
  
                break
  
                ;;
  
      white)
  
                echo you have choose the $manu be the first color
  
                break
  
                ;;
  
      black)
  
                echo you have choose the $manu be the first color
  
                break
  
                ;;
  
      *)
  
                echo i cant hera you
  
      esac
  
done
  
first=$REPLY
  

  
PS3="choose the second color(1-8): "
  
select manu in red green yellow blue voilet light-blue white black;do
  
      case $manu in
  
      red)
  
                echo you have choose the $manu be the second color
  
                break
  
                ;;
  
      green)
  
                echo you have choose the $manu be the second color
  
                break
  
                ;;
  
      yellow)
  
                echo you have choose the $manu be the second color
  
                break
  
                ;;
  
      blue)
  
                echo you have choose the $manu be the second color
  
                break
  
                ;;
  
      voilet)
  
                echo you have choose the $manu be the second color
  
                break
  
                ;;
  
      light-blue)
  
                echo you have choose the $manu be the second color
  
                break
  
                ;;
  
      white)
  
                echo you have choose the $manu be the second color
  
                break
  
                ;;
  
      black)
  
                echo you have choose the $manu be the second color
  
                break
  
                ;;
  
      *)
  
                echo i cant hera you
  
      esac
  
done
  
second=$REPLY
  

  
let color1=40+first
  
let color2=40+second
  

  
#### while code
  

  
i=1
  
while [ $i -le 4 ];do
  
      j=1;while [ $j -le $s ];do
  

  
                k=1;while [ $k -le 4 ];do
  
                        m=1;n=1
  
                        while [ $m -le $s ];do
  
                              echo -e "\033[${color1}m\033[0m\c"
  
                              let m++
  
                        done
  
                        while [ $n -le $s ];do
  
                              echo -e "\033[${color2}m\033[0m\c"
  
                              let n++
  
                        done
  
                        let k++
  
                done
  
                echo
  
                let j++
  
      done
  
      j=1;while [ $j -le $s ];do
  
                k=1;while [ $k -le 4 ];do
  
                        m=1;n=1
  
                        while [ $m -le $s ];do
  
                              echo -e "\033[${color2}m\033[0m\c"
  
                              let m++
  
                        done
  
                        while [ $n -le $s ];do
  
                              echo -e "\033[${color1}m\033[0m\c"
  
                              let n++
  
                        done
  
                        let k++
  
                done
  
                echo
  
                let j++
  
      done
  
      let i++
  
done
  

  
##ending


页: [1]
查看完整版本: 第14章练习,shell脚本编程实例-1