LinuxSir.cn,穿越时空的Linuxsir!

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

工作不好找,无聊写了几个小bash,

[复制链接]
发表于 2009-3-25 16:52:59 | 显示全部楼层 |阅读模式
 楼主| 发表于 2009-3-25 16:56:58 | 显示全部楼层
详细图,可到我空间
http://user.qzone.qq.com/1237697 ... rlReportBlankZone.0

欢迎大家与我交流,
代码有点多,上传一部分

是查单词的

#!/bin/bash
#Writer:<lop>  QQ:<123769752> mail:<g_linux@qq.com>   <- 璇蜂繚鎸佸師鍚嶈浆杞斤紙鍊熸鎵惧伐浣滐級锛屾杩庢潵涓庢垜浜ゆ祦'
#---------init function
check()
{
csize=$(wc ./.libcharacter -c)
csize=${csize%%./.libcharacter}
wsize=$(wc ./.libcharacter -w)
wsize=${wsize%%./.libcharacter}
if (($csize>0&&$wsize>0));then
cp -R ./.libcharacter ./.libcharacter.bak
init
else
cp -R ./.libcharacter.bak ./.libcharacter
init
fi
}

init()
{
clear
black='\E[30;47m'
red='\E[31;400m'
green='\E[32;400m'
yellow='\E[33;400m'
blue='\E[34;400m'
magenta='\E[35;400m'
cyan='\E[36;400m'
white='\E[37;400m'
sort .libcharacter --output=./.libcharacter
menu
}

menu()
{
echo MENU
echo ============================
echo -e $yellow '[ 0 ].Display ALL word'
echo ============================
#tput cup 2 0
echo -e $red "[ 1 ].Find character"
#tput cup 4 0
echo ============================
echo -e $blue "[ 2 ].Add  character"
#tput cup 6 0
echo ============================
echo -e $cyan "[ 3 ].Modify character"
#tput cup 8 0
echo ============================
echo -e $green "[ 4 ].Exit";tput sgr0
echo ============================
#tput cup 10 0
read -p "choice one:" NO
input $NO
}

findcharacter()
{
declare -x tmpchar
read -p "Input will Find character[0=exit]:" character
if [[ $character == '0' ]];then
clear
menu
else
tmpchar=$(grep -w  $character ./.libcharacter)
varsta=$?
if  (( $varsta == 0 ));then
listchar
elif (( $varsta==1));then
tmpchar=$(grep -G  $character ./.libcharacter)
if (($?==0));then
listchar
else
echo -e "NO find $red $character";tput sgr0
fi
fi
findcharacter
fi
}

input()
{
case $1 in
0)
display ;;
1)
findcharacter ;;
2)
addcharacter ;;
3)
modify ;;
4)
clear
bash main.sh
exit;;
esac
}

listchar()
{
clear
echo =====++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=====
echo -e $red $tmpchar|uniq ; tput sgr0
echo =====++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=====
menu
}

modify()
{
declare tmp
read -p "input modify character:" mod
grep $mod .libcharacter
if (( $? == 0 ));then
grep $mod -wv ./.libcharacter >tmp
lsize=$(cat ./.libcharacter|wc -m)
tsize=$(cat tmp|wc -m)
read -p "input character mean:" zh
mod="$mod $zh"
if (( $lsize-$tsize <= 20 ));then #鏈€澶氫慨鏀?0瀛楃
cat tmp > ./.libcharacter
echo $mod >> ./.libcharacter
rm -f tmp
echo "modify over"
sleep 1
listchar $mod
fi
else
echo -e -n "NO find $red '$mod' ";tput sgr0;echo -n -e "are you add $red '$mod' ?[y,n]";tput sgr0
read tmp
if [[ $tmp == 'Y' || $tmp == 'y' ]];then
clear
addcharacter
else
clear
menu
fi
fi
}

addcharacter()
{
read -p "input add english-character(0=exit):" var
if [[ $var == '0' ]];then
clear
menu
else
read -p "input add zh-mean:" zh
var="$var $zh"
echo $var >> ./.libcharacter
addcharacter
fi
}

display()
{
dialog --textbox .libcharacter  0 0
}
#--------call function----
check
bash main.sh
kill -9 $$
回复 支持 反对

使用道具 举报

 楼主| 发表于 2009-3-25 16:58:14 | 显示全部楼层
小游戏

#!/bin/bash
#Writer:<lop>  QQ:<123769752> mail:<g_linux@qq.com>   <- 璇蜂繚鎸佸師鍚嶈浆杞斤紙鍊熸鎵惧伐浣滐級锛屾杩庢潵涓庢垜浜ゆ祦'
init()
{
clear
declare -x a b c d money chang change time first=0 two=0 three=0 four=0
black='\E[30;47m'
red='\E[31;400m'
green='\E[32;400m'
yellow='\E[33;400m'
blue='\E[34;400m'
magenta='\E[35;400m'
cyan='\E[36;400m'
white='\E[37;400m'
reset=`tput sgr 0`
house=",~(Y)Q>"
sum=100
start1=0
rand=0
sleep 1
a=1
b=2
c=3
d=4
win1=0
win2=0
win3=0
win4=0
money=1000
clear
input
}

input()
{
echo you have MONEY:'$'$money
first=0
two=0
three=0
four=0
read -p "input money:" change
if (($change > $money));then
echo "YOU not enough money!"
input
fi
read -p "input choice house[1,2,3,4]:" chang
if (($chang > 0 && $chang <=4));then
:
else
echo "Not have you choice NO.!"
input
fi

clear

tput cup 1 0 ;echo "=============================================================================================================================="
tput cup 3 0 ;echo "=============================================================================================================================="
tput cup 5 0 ;echo "=============================================================================================================================="
tput cup 7 0 ;echo "=============================================================================================================================="
tput cup 9 0 ;echo "=============================================================================================================================="
tput cup 12 24 ;echo -e "=======you moneymoney=========NO.1:<$white$first$reset>===NO.2:<$red$two$reset>===NO.3:<$blue$three$reset>===NO.4:<$cyan$four$reset>========"
tput cup 2 0 ;echo ">"
tput cup 4 0 ;echo ">"
tput cup 6 0 ;echo ">"
tput cup 8 0 ;echo ">"
time=0
sleep 1
start
}

drew1()
{
((win1=$win1+$1))
tput cup 2 $win1
echo -e -n $white $house;tput sgr0
sleep 0.3
first=$win1
if (( $win1 >= 100 ));then
time=100
win1=0
win2=0
win3=0
win4=0
start $win1 $a
fi
}

drew2()
{
((win2=$win2+$1))
tput cup 4 $win2
echo -n -e $red $house;tput sgr0
sleep 0.3
two=$win2
if (( $win2 >= 100 ));then
time=100
win1=0
win2=0
win3=0
win4=0
start $win2 $b
fi
start
}

drew3()
{
((win3=$win3+$1))
tput cup 6 $win3
echo -n -e $blue $house;tput sgr0
sleep 0.3
three=$win3
if (( $win3 >= 100 ));then
time=100
win1=0
win2=0
win3=0
win4=0
start $win3 $c
fi
}

drew4()
{
((win4=$win4+$1))
tput cup 8 $win4
echo -n $house
sleep 0.3
four=$win4
if (( $win4 >= 100 ));then
time=100
win1=0
win2=0
win3=0
win4=0
start $win4 $d
fi
}

start()
{
times=$1
winer=$2
while true
do
if (( $time >= 99 ))
then
break
fi
clear
tput cup 1 0 ;echo "==============================================================================================================================[鍙风爜]"
tput cup 3 0 ;echo "==============================================================================================================================[1]"
tput cup 5 0 ;echo -e "====================================================$green Time:<`date +%T`>$reset =========================================================[2]"
tput cup 7 0 ;echo "==============================================================================================================================[3]"
tput cup 9 0 ;echo "==============================================================================================================================[4]"
tput cup 12 20 ;echo -e "=======Have money($money-$change))$=========NO.1:<$white$first$reset>===NO.2:<$red$two$reset>===NO.3:<$blue$three$reset>===NO.4:<$cyan$four$reset>========"
rand1=$RANDOM
rand2=$RANDOM
((curent=$rand1 % 4 + 1))
((winerr=$rand2 % 10 + 1 ))
case  $curent in
1)
drew1 $winerr
drew2 0
drew3 0
drew4 0
;;
2)
drew2 $winerr
drew1 0
drew3 0
drew4 0
;;
3)
drew3 $winerr
drew1 0
drew3 0
drew4 0
;;
4)
drew4 $winerr  
drew2 0
drew3 0
drew1 0;;
esac
((i++))
done
over $winer
}

over()
{
if (( $money > 0));then
{   if [[ $chang == $1 ]];then
     {
      ((money=$money + $change * 2 ))
        clear
        echo  "WINER锛侊紒锛?moneychange" $1"鍙烽┈鑳滃埄"  "you have $money "
        sleep 3
        input
       }
   else
      {
       ((money=$money-$change))
       clear
       echo "you lose!" $change $1"鍙烽┈鑳滃埄"  "you have $money"
       sleep 3
       if (( $money > 0 ));then
        input
       fi
       }
    fi
}
else
    clear
   dialog --pause "YOU LOSE" 10 30 3
bash main.sh   
exit
fi
}
init
回复 支持 反对

使用道具 举报

 楼主| 发表于 2009-3-25 16:59:14 | 显示全部楼层
主题部分
#!/bin/bash
#Writer:<lop>  QQ:<123769752> mail:<g_linux@qq.com>   <- 璇蜂繚鎸佸師鍚嶈浆杞斤紙鍊熸鎵惧伐浣滐級锛屾杩庢潵涓庢垜浜ゆ祦'
init()
{
black='\E[30;47m'
red='\E[31;400m'
green='\E[32;400m'
yellow='\E[33;400m'
blue='\E[34;400m'
magenta='\E[35;400m'
cyan='\E[36;400m'
white='\E[37;400m'
reset=`tput sgr0`
displaye
}

displaye()
{
clear
echo 'Menu        Writer:<lop>  QQ:<123769752> mail:<g_linux@qq.com>   <- 璇蜂繚鎸佸師鍚嶈浆杞斤紙鍊熸鎵惧伐浣滐級锛屾杩庢潵涓庢垜浜ゆ祦'
echo ===========================
echo -e $green "1.Exit"  "閫€鍑?$red锛佸嵄闄╋紒$reset$green缁撴潫鎵€鏈夋鍦ㄨ繍琛岀殑bash shell>";tput sgr0
echo --------------------
echo -e $red "2.Mount disk" 鎸傜洏
echo --------------------
echo -e $yellow "3.Movie"   鐢靛奖
echo --------------------
echo -e $cyan "4.Music"     闊充箰
echo --------------------
echo -e $magenta "5.Shutdown Computer" 鍏虫満
echo -e $red--------------------
echo -e $white" 6.findchar" 鏌ュ瓧
echo ===========================
echo -e " 7.game" 娓告垙   '     ' "8. dball"  
echo ===========================
echo -e $white \<-Date-\>;tput sgr0
echo -e $blue
cal -3m;tput sgr0
}


readvar()
{
read -p "chioce <1,2,3,4 or 5>:" var
call $var
}
call()
{
case "$1" in
"1" | "exit" )
sudo pkill -9 'dialog'
sudo pkill -9 'bash';;
"2" | "mount" )
sudo bash usb.sh ;;
"3" | "movie" )
bash Mpl_Std.sh ;;
"4" | "music" )
bash music.sh;;
"5" | "halt" )
sudo bash poweroff.sh;;
"6"  | "fchar" )
bash findchar.sh;;
"7" | "game" )
bash game.sh ;;
"8"| "dball" )
bash dball.sh
esac
}

beatiful()
{
while true
do
((k++))
if (($k>7));then
clear
break
fi
tput cup 26 22
for i in 1 2 3 4  
do
sleep 0.09
case $i in
1) tput cup 2 0; echo '-';;
2) tput cup 2 0; echo '\';;
3) tput cup 2 0; echo '|';;
4) tput cup 2 0; echo '/';;
esac
tput cup 26 22
done
done
}
init
readvar
beatiful
sudo pkill -9 dialog
回复 支持 反对

使用道具 举报

 楼主| 发表于 2009-3-25 17:00:00 | 显示全部楼层
来个挂盘的

#!/bin/bash
#Writer:<lop>  QQ:<123769752> mail:<g_linux@qq.com>   <- 璇蜂繚鎸佸師鍚嶈浆杞斤紙鍊熸鎵惧伐浣滐級锛屾杩庢潵涓庢垜浜ゆ祦'
declare -i -x glale=0

init()
{
declare len psw=usb
if [ -e ./.passwd ];then
     psw=$(dialog --passwordbox "input passwd box" 10 35 --stdout)
     cat ./.passwd|grep -wx $psw
    if (( $? == 0 ));then
    glale=1
    else
    dialog --msgbox "passwd error" 10 35
    glale=0
    init
    fi
else
    clear
    touch ./.passwd
    read -p "input init passwd:" psw
    len=$(expr length $psw)
    clear
    if (( $len-1 <=0 ));then
    echo "passwd  too short"
    rm -r ./.passwd
    sleep 3
    init
    else
    echo $psw > ./.passwd
    init
    fi
fi

if (( $UID == 0 ));then
glale=1
else
glale=0
clear
echo "you must login root user"
sleep 2
bash main.sh
exit
fi

if [ -e /usr/bin/dialog ];then
       glale=1
else
  glale=0
  echo "NO dialog file"
  sleep 3
  exit
fi

if (( $glale == 1 ));then
input
fi
}

#------------------

Fmount()
{
declare finddev
ls -a /dev/|grep -wx $1
finddev=$?
      if [ -e /media/$1 ];then
             UFmount $1
       else
                     if (( $finddev == 0 ));then            
             mkdir -p /media/$1 2>/dev/null
             sleep 1
             mount /dev/$1 /media/$1 2>/dev/null
             nautilus /media/$1
                      input
                              else
                                 clear
                                 
                                 echo  -en "NO search" '\E[77;35m'"\033[1m $1\033[0m" "media file"
                                 sleep 3
                                 input
                         fi
fi
}
#----------------

UFmount()
{
if [[ -e /media/$1 ]];then
umount /media/$1
rm -fr /media/$1
input
else
echo  -en "NO search" '\E[77;35m'"\033[1m $1\033[0m" "media file"
sleep 3
input
fi
}

#------------------
input()
{
declare -i num
declare var  stu



if (( $glale == 0 )) ;then
    read -p "input media name:" var
          num=`expr length $var`
                  if (( $num-0 <= 0 ));then
                                           echo "!!!please input media."
                                           sleep 3
                                                 input
                  else
                                    Fmount $var
                  fi
else
        var=$(dialog --extra-button --extra-label "M_passwd" --max-input 16 --help-button --inputbox "input media" 10 63 --stdout)  # var=`dialog --inputbox "ddd" 10 45 --stdout` 鍔熻兘涓€鏍?         stu=$?
      if (( $stu == 3 ));then
         rm -r ./.passwd
         init
         fi

         if (( $stu == 2 ));then
             ls /dev|sort|more
               input
         fi

        if (( $stu == 1 ));then
           bash main.sh
           exit
         fi
                        num=$(expr length $var)
       
               
                 if (( $num <= 0 ));then
                                 
                                        dialog --pause "!!!please input media" 8 35 3
                                            input
                  else

                                   Fmount $var
                  fi
fi
}         

#----------main()                          
init
kill -9 $$
回复 支持 反对

使用道具 举报

 楼主| 发表于 2009-3-25 17:01:05 | 显示全部楼层
来个双色球、

#!/bin/bash
#Writer:<lop>  QQ:<123769752> mail:<g_linux@qq.com>   <- 璇蜂繚鎸佸師鍚嶈浆杞斤紙鍊熸鎵惧伐浣滐級锛屾杩庢潵涓庢垜浜ゆ祦'
checkenv()
{
declare glole=1
which dialog 1>/dev/null
if (($?==0))
then
glole=1
else
echo "NO search dialog"
exit 0
fi
init
}
init()
{
stty -echo
declare -x arry=(0 0 0 0 0 0 0)
class 0
}

class()
{
for ((r=$1;r<7;r++))
{
first=$RANDOM
arry[r]=$((first%33+1))
if ((r>5));then
arry[r]=$((first%16+1))
fi
}
check
}

check()
{
##鎺掑簭
for (( r=0;r<6;r++ ))
{
for (( c=0;c<6-1;c++ ))
{
if (( ${arry[c]} > ${arry[c+1]} ));then
      {
       t=${arry[c]}
      arry[c]=${arry[c+1]}
     arry[c+1]=$t
     }
     fi
    }
  }

for((i=0;i<6;i++))
{
for((r=0;r<6-1;r++))
{
  if((${arry[r]} == ${arry[r+1]}));then
  class `expr $r+1`
  fi

  }

}
  if(( $i >= 6));then
  disp
  fi
}
disp()
{
echo '#result'>out
for((r=0;r<7;r++))
{
echo -n ${arry[r]} ' ' >>out
}
echo >>out
}

main()
{
while true
do
echo 100|dialog --gauge "姝e湪鐢熸垚" 0 0
sleep 0.2
checkenv
dialog --extra-button --extra-label "history" --textbox out 0 0
dr=$?
if (($dr == 0));then
main
exit 0
elif (($dr == 3));then
clear
dialog --textbox  /tmp/dbhistory 0 0
elif (($dr == 1 ));then
cat out>>/tmp/dbhistory
stty echo
bash main.sh
sudo kill $$
break
fi
((i++))
done
}
main
回复 支持 反对

使用道具 举报

 楼主| 发表于 2009-3-25 17:03:44 | 显示全部楼层
技术水平有限。写的不好,献丑了
回复 支持 反对

使用道具 举报

 楼主| 发表于 2009-3-25 17:05:13 | 显示全部楼层
看效果图到
http://user.qzone.qq.com/1237697 ... rlReportBlankZone.0


相册里面 bash shell
回复 支持 反对

使用道具 举报

发表于 2009-3-25 23:07:13 | 显示全部楼层
@@  仰慕一下下
回复 支持 反对

使用道具 举报

发表于 2009-3-27 09:46:45 | 显示全部楼层
帮顶一下哈。
回复 支持 反对

使用道具 举报

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

本版积分规则

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