红联Linux门户
Linux帮助

shell里边子函数与主函数的实例

发布时间:2006-04-17 10:26:50来源:红联作者:莫少剑
很简单,但能说明白主函数和子函数的实现
#!/bin/bash
square()
{
echo "square of $1 is \c"
echo "$1*$1"|bc
}
########################
cube()
{
echo "cube of $1 is \c"
echo "2^$1"|bc
}
#######################
power()
{
echo "raising 2 to the power of $1 is \c"
}

while getopts s:c:p: option
do
case $option in
s)square $OPTARG;;
c)cube $OPTARG;;
p)power $OPTARG;;
esac
done
文章评论

共有 0 条评论