首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

shell兑现的数字转换脚本(用-h选项查看help信息)

2012-08-25 
shell实现的数字转换脚本(用-h选项查看help信息)#!/bin/bashcheck_opts(){if [ -z $src ] then echo u

shell实现的数字转换脚本(用-h选项查看help信息)

#!/bin/bashcheck_opts(){if [ -z "$src" ]; then echo "use -s to specify the original radix"exit 1fi if [ -z "$des" ]; then echo "use -d to specify the final radix"exit 1fi }if [ "$#" -lt 1 ]; then cat <<HELPEOFuse option -h to get more information .HELPEOFexit 0fi while getopts "s:d:h" optdocase $opt ins)src=$OPTARG;;d)des=$OPTARG;;h)cat <<HELPEOFNAMEbaseconv.sh - convert number to a different radixSYNOPSISbasecon.sh [OPTION]... [NUMBER]...DESCRIPTIONbaseconv.sh is used to convert number to a different radix, NUMBER specify the number which desire convertion .-sspecify the original radix-dspecify the final radixHELPEOFexit 0;;esacdonecheck_opts shift $((OPTIND-1))if [ $# -lt 1 ]; then echo "please input at least one number !"fii=0while [ $# -gt 0 ] donum=$1shift 1if [ $src -eq $des ]; thenecho $numcontinue fiif [ ! $src -eq "10" ]; then((num=$src#$num))#echo $numfiif [ $des -eq "10" ]; then echo $numelse echo $(echo "obase=$des;$num" | bc)fi done
?

热点排行