全部博文(395)
分类: LINUX
2011-08-15 16:07:08
一些经典的shell脚本例子
一。实现屏幕闪烁功能
#/bin/bash
clear
declare counter1=1
declare counter2
while [ "$counter1" -lt 1000 ]
do
echo "Warning: There's a bug in your program"
let counter2=1
while [ "$counter2" -lt 200 ]
do
let counter2="$counter2 + 1"
done
clear
let counter2=1
while [ "$counter2" -lt 200 ]
do
let counter2="$counter2 + 1"
done
let counter1="$counter1 + 1"
done
二。函数调用
#!/bin/bash
clear
function verify
{
if [ $# -ne 2 ]
then
echo "Wrong number of arguments!"
else
if [ $1 == "Bob" ] && [ $2 == 555 ]
then
return 0
else
return 2
fi
fi
}
verify Bob 555
case $? in
0) echo "verified"
;;
1) echo "Wrong number of arguments"
;;
2) echo "Rejected"
;;
esac