指令: sh check_num.sh -i Num or sh check_num.sh -f Num
說明: 利用正規表示法判斷
#! /bin/bashfloatExp="^(-?\d+)(\.\d+)?$"intExp="^-?\d+$"exp=""exp=${intExp}if [ $# != 2 ] ; thenecho wrong arg nums,please input one argexit 1ficase $1 in"-f")exp=${floatExp};;"-i")exp=${intExp};;*)echo option shuld be -i or -fexit 1;;esacif [ `echo $2|grep -P "${exp}"|wc -l` == 1 ] ; thenecho num $2exit 0;elseecho not numexit 1;fi
沒有留言:
張貼留言