小文字から大文字に変換する

#!/bin/sh
#upper.sh [-t] [filename] -t 行頭のみ大文字に変換

INFILE="-"
OPTIONS="t"
TOP="FALSE"
FLAG="TRUE"

#小文字を大文字に変換する関数
function tr_upper(){
    local LLINE="$1"
    local LTMP1=""
    local LTMP2=""
    local LTMP3=""
    local LNLIN=""

    LTMP3="$LLINE"
    LTMP2="${LTMP3#?}"
    LTMP3="$LLINE"
    LTMP1="${LTMP3%${LTMP2}}"

    while [ "" != "$LTMP1" ]; do
        if [ "(" "(" "TRUE" = "$TOP" ")" -a "(" "TRUE" = "$FLAG" ")" ")" \
            -o "(" "FALSE" = "$TOP" ")" ]; then
            case "$LTMP1" in
                a) LTMP1="A" ;;
                b) LTMP1="B" ;;
                c) LTMP1="C" ;;
                d) LTMP1="D" ;;
                e) LTMP1="E" ;;
                f) LTMP1="F" ;;
                g) LTMP1="G" ;;
                h) LTMP1="H" ;;
                i) LTMP1="I" ;;
                j) LTMP1="J" ;;
                k) LTMP1="K" ;;
                l) LTMP1="L" ;;
                m) LTMP1="M" ;;
                n) LTMP1="N" ;;
                o) LTMP1="O" ;;
                p) LTMP1="P" ;;
                q) LTMP1="Q" ;;
                r) LTMP1="R" ;;
                s) LTMP1="S" ;;
                t) LTMP1="T" ;;
                u) LTMP1="U" ;;
                v) LTMP1="V" ;;
                w) LTMP1="W" ;;
                x) LTMP1="X" ;;
                y) LTMP1="Y" ;;
                z) LTMP1="Z" ;;
            esac

            LTMP3="$LTMP1"
            if [ "(" "TRUE" = "$FLAG" ")" -a "(" "" = "${LTMP3#[A-Z]}" ")" ]
            then
                FLAG="FALSE"
            fi
        fi
        if [ "." = "$LTMP1" ]; then
            FLAG="TRUE"
        fi
        LLINE="$LTMP2"
        LNLIN="$LNLIN$LTMP1"
        LTMP3="$LLINE"
        LTMP2="${LTMP3#?}"
        LTMP3="$LLINE"
        LTMP1="${LTMP3%${LTMP2}}"
    done
    echo "$LNLIN"
}

#オプション処理
while getopts $OPTIONS opt $@ ; do
    case "$opt" in
        t) TOP="TRUE" ;;
        *) exit -1 ;;
    esac
done

#処理するファイル名のオプション処理
shift $(( $OPTIND -1 ))
if [ $# -eq 0 ]; then
    INFILE=""
elif [ $# -eq 1 ]; then
    if [ "\-" = "$1" ]; then
        INFILE=""
    else
        INFILE="$1"
        if [ ! "(" -f $INFILE ")" ]; then
            echo "ファイルが読めません" 1>&2
            exit -1
        fi
    fi
else
    echo "オプションが多いです" 1>&2
    exit -1
fi

#メイン処理
if [ "" = "$INFILE" ]; then
    while read line ; do
        tr_upper "$line"
    done
else
    while read line ; do
        tr_upper "$line"
    done < "$INFILE"
fi