|
发表于 2007-1-11 11:02:15
|
显示全部楼层
- #!/bin/bash
- if [ "x$1" == "x" ];then
- str="-123--111,-101-0,201-205,-300-12,1,2"
- else
- str=$1
- fi
- index=0;
- for i in ${str//","/" "};do
- if [ `expr index $i "-"` -eq 0 ];then
- res[$index]=$i
- index=$((index+1))
- else
- if [ `expr match $i '-[0-9][0-9]*--[0-9][0-9]*'` -ne 0 ];then
- low=${i%--*}
- high=${i#-*-}
- for((j = $low; j <= $high; j++));do
- res[$index]=$j
- index=$((index+1))
- done
- continue
- fi
- if [ `expr match $i "-[0-9][0-9]*-[0-9][0-9]*"` -ne 0 ];then
- low=${i%-*}
- high=${i##*-}
- for((j = $low; j <= $high; j++));do
- res[$index]=$j
- index=$((index+1))
- done
- continue
- fi
- if [ `expr match $i '[0-9][0-9]*-[0-9][0-9]*'` -ne 0 ];then
- low=${i%-*}
- high=${i#*-}
- for((j = $low; j <= $high; j++));do
- res[$index]=$j
- index=$((index+1))
- done
- continue
- fi
- fi
- done
- echo ${res[@]}
复制代码 这回可以解决负数的问题了,就是做的比较麻烦。 |
|