case while for

#!/bin/bash
#create by howhy 20161214
#mysql server start stop restart
. /etc/init.d/functions
mysqldir="/opt/local/mysql"
[ -e "$mysqldir" ] && cd "$mysqldir"
usage(){
echo "$0 {start|stop|restart}"
exit 2
}
start(){
[ -f $mysqldir/mysqld.pid ] && {
echo "mysql server is running..."
exit 2
}
./bin/mysqld_safe &>/dev/null &
[ $? -eq 0 ] && action "mysql server start..." /bin/true
}
stop(){
[ ! -f $mysqldir/mysqld.pid ] && {
echo "mysql server has stopped..."
exit 2
}
./bin/mysqladmin -uroot -pwoshishui shutdown &>/dev/null
[ $? -eq 0 ] && action "mysql server stop..." /bin/true
}
[ $# -ne 1 ]&&{
usage
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
usage
esac

#!/bin/bash
a=1
sum=0
while [ $a -le 100 ]
do
#let sum=sum+a
#let a=a+1
((sum+=a))
((a++))
done
echo $sum

while 读取文件

while read line

do

     echo $line

done </opt/file.txt

for a in {1..10};do echo $a ;done

for((a=1;a<=100;a++));do let sum=sum+a ;done

 

posted @ 2016-12-14 17:57  howhy  阅读(132)  评论(0编辑  收藏  举报