LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 692|回复: 2

我写的一个菜单,请帮我缩减一下代码!thanks

[复制链接]
发表于 2005-12-26 19:32:21 | 显示全部楼层 |阅读模式
#!/bin/bash
#----------ding yi k-----------#


lk()
{
x=$1
y=$3
c=$5
while [ $x -lt $2 ] ;do

while [ $y -lt $4 ] ;do

        echo -en "\33["$x";"$y"H"
        echo -en "\33[4"$c"m"
        echo -n " "       

        let y+=1
done
        let x+=1
        y=$3
done

echo
echo -en "\33[0m"
}



#---------start-------------#
# lk x1 x2 y1 y2 c#
# y1---------y2
# x1|       |
#   |       |
#   |       |
#   |       |
# x2----------
#
# c:ce



#-------------chu shi bian lian -------------------#

echo -en "\33[44m"      #di ce
clear
lk 5 22 16 65 0                #di kuang
lk 4 21 14 63 7         #shang kuang

echo -en "\33[31m\33[47m"
echo -en "\33[4;15H+-----------Linux 2.4.22-----hecheng----------+"
echo -en "\33[5;15H|                                             |"
echo -en "\33[6;15H|                                             |"
echo -en "\33[7;15H|                                             |"
echo -en "\33[8;15H|                                             |"
echo -en "\33[9;15H|                                             |"
echo -en "\33[10;15H|                                             |"
echo -en "\33[11;15H|                                             |"
echo -en "\33[12;15H|                                             |"
echo -en "\33[13;15H|                                             |"
echo -en "\33[14;15H|                                             |"
echo -en "\33[15;15H|                                             |"
echo -en "\33[16;15H|                                             |"
echo -en "\33[17;15H|                                             |"
echo -en "\33[18;15H|                                             |"
echo -en "\33[19;15H|                          Ver.0.0.0.1        |"
echo -en "\33[20;15H+---------------------Copyright (c) 2005------+"

echo -en "\33[1m\33[?25l"

t1="--1.xia-xue---"                # title #
t2="--2.hua-xian--"
t3="--3.dong------"



#------------- locate s------------#

ls1()
{
echo -en "\33[44m\33[37m"
echo -en "\33[8;20H"
echo -n $t1

echo -en "\33[47m\33[30m"
echo -en "\33[16;20H"
echo -n $t3
}


ls2()
{

echo -en "\33[44m\33[37m"
echo -en "\33[12;20H"
echo -n $t2

echo -en "\33[47m\33[30m"
echo -en "\33[8;20H"
echo -n $t1
}


ls3()
{

echo -en "\33[44m\33[37m"
echo -en "\33[16;20H"
echo -n $t3

echo -en "\33[47m\33[30m"
echo -en "\33[12;20H"
echo -n $t2
}
#--------------locate w-------------#
lw1()
{
echo -en "\33[44m\33[37m"
echo -en "\33[8;20H"
echo -n $t1

echo -en "\33[47m\33[30m"
echo -en "\33[12;20H"
echo -n $t2
}


lw2()
{

echo -en "\33[44m\33[37m"
echo -en "\33[12;20H"
echo -n $t2

echo -en "\33[47m\33[30m"
echo -en "\33[16;20H"
echo -n $t3
}


lw3()
{

echo -en "\33[44m\33[37m"
echo -en "\33[16;20H"
echo -n $t3

echo -en "\33[47m\33[30m"
echo -en "\33[8;20H"
echo -n $t1
}

#---------------chu shi tilet ------------------#


echo -en  "\33[44m\33[37m"
echo -en "\33[8;20H"
echo -n $t1

echo -en  "\33[47m\33[30m"
echo -en "\33[12;20H"
echo -n $t2

echo -en "\33[16;20H"
echo -n $t3



#--------------start -----------------------------#



a=8

while true ; do

echo -en "\33[47m\33[37m"
read -n 1 l

case $l in


        s)        if [ $a -eq 8 ]  ; then

                        a=$[$a+4]
                        ls2

                elif [ $a -eq 12 ] ; then
               
                        a=$[$a+4]
                        ls3
                else

                        a=8
                        ls1

                fi
                        ;;
           w)        if [ $a -eq 16 ] ;then
               
                        a=12
                        lw2

                elif [ $a -eq 12 ] ; then

                        a=8
                        lw1

                else
               
                        a=16
                        lw3
                fi

                        ;;
       
        d)        if [ $a -eq 8 ]  ; then

                        a=$[$a+4]
                        ls2

                elif [ $a -eq 12 ] ; then
               
                        a=$[$a+4]
                        ls3
                else

                        a=8
                        ls1

                fi
                        ;;

          a)        if [ $a -eq 16 ] ;then
               
                        a=12
                        lw2

                elif [ $a -eq 12 ] ; then

                        a=8
                        lw1

                else
               
                        a=16
                        lw3
                fi
                        ;;
        $REPLY)        if [ $a = "8" ] ;then

                        clear
                        ./xiaxue       
                        break
       
                elif [ $a = "12" ] ;then

                        clear
                        ./hx
                        break
                else
                        clear
                        ./dong
                        break
                fi
                        ;;

               
       

esac

done
发表于 2005-12-26 20:39:31 | 显示全部楼层

可以用select命令,不过可能没那么好看

当然select还可以嵌套几级子菜单

  1. #!/bin/sh

  2. # $Id: info.sh  2005-12-26 20:40 CST $

  3. # Copyright 2005 Sipingal <sipingal@163.com>.
  4. #

  5. echo '
  6. *********************************************************
  7. *                  Menu: System info                    *
  8. *                    version: 0.1                       *
  9. *********************************************************
  10. '


  11. select item in "Monitor network." "Monitor running process." "The current login user."  "Quit."
  12. do
  13. {
  14.     case $item in
  15.         "Monitor network.")
  16.         netstat -lanp | less -isr
  17.         exec sh $0
  18.         ;;
  19.         "Monitor running process.")
  20.         ps auxww | less -isr
  21.         exec sh $0
  22.         ;;
  23.         "The current login user.")
  24.         w
  25.         exec sh $0
  26.         ;;
  27.         "Quit.")
  28.         break
  29.         ;;
  30.         "*")
  31.         exec sh $0
  32.         ;;
  33.     esac
  34. }
  35. done
复制代码
回复 支持 反对

使用道具 举报

发表于 2005-12-27 02:37:32 | 显示全部楼层
没有充分发挥bash的特性!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表