Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2295726
  • 博文数量: 395
  • 博客积分: 10994
  • 博客等级: 上将
  • 技术积分: 5586
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-17 19:49
文章存档

2014年(1)

2013年(10)

2012年(74)

2011年(303)

2010年(7)

分类: 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

阅读(864) | 评论(0) | 转发(0) |
0

上一篇:shell脚本杂烩

下一篇:shell 语法杂烩

给主人留下些什么吧!~~