|
发表于 2005-1-28 00:24:34
|
显示全部楼层
不好意思,考古了,作作练习
- [xiaocong@xiaocong shell]cat zfx
- # set up default values
- bianshu=5
- fuhao=*
- #process command options
- while getopts f:b: option
- do
- case "$option"
- in
- f) fuhao=$OPTARG;;
- b) bianshu=$OPTARG;;
- \?) echo "usage ./zfx [-b n] [-f ?]"
- echo "-b border numb of spuare is n"
- echo "-f symble to be printed is ?"
- exit 1;;
- esac
- done
- hangshu=$(expr $bianshu \* 2 - 1)
- hanghao=1
- while [ $hanghao -le $hangshu ]
- do
- if [ $hanghao -le $bianshu ]
- then
- shuojinshu=$hanghao
- else
- shuojinshu=$(expr $bianshu \* 2 - $hanghao)
- fi
- konggeshu=$(expr $hangshu - 2 \* $shuojinshu + 1)
- fuhaoshu=$(expr 2 \* $shuojinshu - 1)
- i=1
- while [ $i -le $konggeshu ]
- do
- echo -e ' \c'
- i=$(expr $i + 1)
- done
- j=1
- while [ $j -le $fuhaoshu ]
- do
- echo -e "$fuhao \c"
- j=$(expr $j + 1)
- done
- echo
- hanghao=$(expr $hanghao + 1)
- done
- [xiaocong@xiaocong shell]./zfx
- *
- * * *
- * * * * *
- * * * * * * *
- * * * * * * * * *
- * * * * * * *
- * * * * *
- * * *
- *
- [xiaocong@xiaocong shell]./zfx -i
- usage ./zfx [-b n] [-f ?]
- -b border numb of spuare is n
- -f symble to be printed is ?
- [xiaocong@xiaocong shell]./zfx -b 10 -f @
- @
- @ @ @
- @ @ @ @ @
- @ @ @ @ @ @ @
- @ @ @ @ @ @ @ @ @
- @ @ @ @ @ @ @ @ @ @ @
- @ @ @ @ @ @ @ @ @ @ @ @ @
- @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
- @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
- @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
- @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
- @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
- @ @ @ @ @ @ @ @ @ @ @ @ @
- @ @ @ @ @ @ @ @ @ @ @
- @ @ @ @ @ @ @ @ @
- @ @ @ @ @ @ @
- @ @ @ @ @
- @ @ @
- @
复制代码 |
|