#!/bin/bash check_opts(){ if [ -z "$src" ]; then echo "use -s to specify the original radix" exit 1 fi if [ -z "$des" ]; then echo "use -d to specify the final radix" exit 1 fi } if [ "$#" -lt 1 ]; then cat <<HELPEOF use option -h to get more information . HELPEOF exit 0 fi while getopts "s:d:h" opt do case $opt in s) src=$OPTARG ;; d) des=$OPTARG ;; h) cat <<HELPEOF NAME baseconv.sh - convert number to a different radix SYNOPSIS basecon.sh [OPTION]... [NUMBER]... DESCRIPTION baseconv.sh is used to convert number to a different radix, NUMBER specify the number which desire convertion . -s specify the original radix -d specify the final radix HELPEOF exit 0 ;; esac done check_opts shift $((OPTIND-1)) if [ $# -lt 1 ]; then echo "please input at least one number !" fi i=0 while [ $# -gt 0 ] do num=$1 shift 1 if [ $src -eq $des ]; then echo $num continue fi if [ ! $src -eq "10" ]; then ((num=$src#$num)) #echo $num fi if [ $des -eq "10" ]; then echo $num else echo $(echo "obase=$des;$num" | bc) fi done