Bash for loops on a remote server
<p>I am attempting to run multiple commands via a bash script on a remote server. specifically, the for loop to be run on the remote server is giving me issues.  I suspect it is because I don't know how to properly escape characters or use $().</p>

<p>Below is the code.</p>

<pre><code>ssh (user)@(server) &lt;&lt;EOF
sudo su - (username)
whoami
'for e in $(`ls -lrt /usr/jboss/jbosseap | awk '{print $9}' | grep multichannel`);
do
echo "$e";
done'
</code></pre>

<p>Removing user and server names for obvious reasons.  Just concentrate on the for loop.  when I run that for loop command line (without the $()) its works fine.  Just not sure how to nest it in a remote call.</p>

<p>Thanks very much for any and all help!</p>