I have a script that sends multiple commands after logging in a remote machine via SSH.
Problem is, it's barely readable. I've tried quoting everything with "", but it's terrible (everything appears in pink), and here documents are just as bad (everything appears in gray). I'm using Gedit as an editor, but I tried Emacs as well.
Can I make the editor parse the remotely executed code as code?
#!/bin/bash
function remoteExec()
{
echo "remote execution starting"
ssh -n "$1" << 'EOF'
#the following code is _not_ highlighted by real editors
currIt=\"$2\" #I hope this parameter is passed correctly
while [ "$currIt" -lt 5 ]; do
echo "hello"
currIt=$(($currIt + 1))
done
EOF
}
I'd rather not create a separate script just for these lines, because then I'd have to copy it on the remote machine, or pipe it, and I have arguments too.
EDIT: as Glenn noticed, as far as highlighting goes, there isn't much to do. I'm open to solutions putting the code in a separate script. I need to transfer the code to the remote host then, and pass it the necessary arguments.
<!-- language: lang-sh -->
But I guess it's far from perfect (Bash synthax is anything but strict). – Agostino Mar 4 '14 at 13:45