read s for((r=s;i++<9;)){ s=${s:1}${s::1} t=${s/+0/+10#} ((${s::1},r[r>t]=t)) } echo $r