• + 0 comments

    without tr command

    func() { local flag=1 local line="$1"

    for(( i=0 ; i<${#line}; i++ ))
    do
        char="`${line:$`i:1}"
        if [[ "$char" == ' ' ]]
        then
            if [[ $flag -eq 1 ]]
            then
                echo -n "$char"
                flag=0
            fi
        else
            echo -n "$char"
            flag=1
        fi
    done
    

    }

    while read -r line do func "$line" echo done