Chinaunix首页 | 论坛 | 博客
  • 博客访问: 209093
  • 博文数量: 136
  • 博客积分: 2919
  • 博客等级: 少校
  • 技术积分: 1299
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-11 09:08
文章分类

全部博文(136)

文章存档

2013年(1)

2011年(135)

我的朋友

分类: Python/Ruby

2011-03-11 10:04:12

1. case expressions example--customize cal command
# cal: nicer interface to /usr/bin/cal

case $# in
0) set `date`; m=$2; y=$6;;
1) m=$1; set `date`; y=$6;;
*) m=$1; y=$2;;
esac

case $m in
jan*|Jan*) m=1;;
feb*|Feb*) m=2;;
*) y=$m; m=" ";;
esac

/usr/bin/cal $m $y

2.  for and if expression example--which cmd
#which cmd: which cmd in PATH is executed, version 1

case $# in 
0) echo ' Usage: which command' 1>&2; exit 2
esac
for i in `echo $PATH | sed 's/^:/.:/
                            s/::/:.:/g
                            s/:$/:./
                            s/:/ /g'`
do
          if test -f $i/$1  #use test -x if you can 
          then
                   echo $i/$1
            exit 0
         fi
done 
exit 1

3. for, while, until example-watch for someone to log in
# watchfor: watch for someone to log in

#PATH=/bin; /usr/bin

case $# in
0) echo 'Usage: watchfor person' 1>&2; exit 1
esac

until who | egrep "$1"
do
         sleep 60
done
阅读(347) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~