Bash pass multiple commands to SSH and make readable
You're quoting the heredoc terminator, so $2 will certainly not be expanded

When you want to pass multiple commands to ssh, wrap them as a single script to an interperter, thus ssh sees one single command.

Lots of whitespace for readability.

And yes, not much opportunity for syntax highlighting.

Since you need variable expansion within the script, you need to worry about quoting variables you want to be expanded on the remote host. I changed the while loop to a for loop to minimize the number of $-signs to escape.

If the script you want to send is more complex, be careful about how you use single and double quotes.

function remoteExec()
{
    echo "remote execution starting"
    ssh -n "$1" &lt;&lt; EOF
        bash -c '
            for (( currIt="$2"; currIt &lt; 5; currIt++ )); do
                echo "hello"
            done
        '
EOF
}




Given an arbitrary number of args:

function remoteExec()
{
    local host=$1
    local startIt=$2
    local quotedArgs
    shift 2
    for arg in "$@"; do
        quotedArgs+="\"$arg\" "
    done

    echo "remote execution starting"
    ssh -n "$host" &lt;&lt; EOF
        bash -c '
            for (( currIt="$startIt"; currIt &lt; 5; currIt++ )); do
                echo "hello"
            done
            args=( $quotedArgs )
            printf "%s\n" "\${args[@]}"   # escape this sigil
        '
EOF
}

remoteExec host 3 arg1 arg2 "this is arg3"