title: How to execute a remote command over ssh with arguments?
body: <p>In my <code>.bashrc</code> I define a function which I can use on the command line later:</p>
  
  <pre><code>function mycommand() {
      ssh user@123.456.789.0 cd testdir;./test.sh "$1"
  }
  </code></pre>
  
  <p>When using this command, just the <code>cd</code> command is executed on the remote host; the <code>test.sh</code> command is executed on the local host. This is because the semicolon separates two different commands: the <code>ssh</code> command and the <code>test.sh</code> command. </p>
  
  <p>I tried defining the function as follows (note the single quotes):</p>
  
  <pre><code>function mycommand() {
      ssh user@123.456.789.0 'cd testdir;./test.sh "$1"'
  }
  </code></pre>
  
  <p>I tried to keep the <code>cd</code> command and the <code>test.sh</code> command together, but the argument <code>$1</code> is not resolved, independent of what I give to the function. It is always tried to execute a command</p>
  
  <pre><code>./test.sh $1
  </code></pre>
  
  <p>on the remote host. </p>
  
  <p>How do I properly define <code>mycommand</code>, so the script <code>test.sh</code> is executed on the remote host after changing into the directory <code>testdir</code>, with the ability to pass on the argument given to <code>mycommand</code> to <code>test.sh</code>?</p>