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
阅读(376) | 评论(0) | 转发(0) |