只用bash:convert_date () { local months=( JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC ) local i for (( i=0; i<11; i++ )); do [[ $2 = ${months[$i]} ]] && break done printf "%4d%02d%02d\n" $3 $(( i+1 )) $1}然后像这样调用它d=$( convert_date 27 JUN 2011 )或者,如果“旧”日期字符串存储在变量中d_old="27 JUN 2011"d=$( convert_date $d_old ) # not quoted