title: bash function "command not found"
body: <p>I've created a function to check for the existence of a file on a remote server, but I'm getting the error "ssh: command not found" when I try to call the function. Here's the function:</p>
  
  <pre><code>remote_file_exists() {
      local SERVER="$1"
      local PATH="$2"
      local FILE="$3"
      FILE_EXISTS=`ssh "$SERVER" \'find "$PATH" -name \"$FILE\"\'`
      if [ -z $FILE_EXISTS ]; then
          return 1
      else
          return 0
      fi
  }
  </code></pre>
  
  <p>I'm calling the function like this:</p>
  
  <pre><code>if ( remote_file_exists $REMOTE_SERVER "$REMOTE_PATH/" $REMOTE_FILE ); then
      echo "$REMOTE_PATH/$REMOTE_FILE exists on $REMOTE_SERVER"
  ...
  </code></pre>
  
  <p>The error I'm getting:</p>
  
  <pre><code>myscript.sh: line x: ssh: command not found
  </code></pre>
  
  <p>The value of 'x' in the error is the line number of the line in the function that starts with "FILE_EXISTS=". </p>
  
  <p>I suspect this has something to do with not quoting correctly, but I can't figure it out. What am I doing wrong?</p>
  
  <p><strong>EDIT:</strong> Thanks to Cfreak for the good catch on the PATH variable name. Once I fixed that I got a different error:</p>
  
  <pre><code>bash: find &lt;MYPATH&gt; -name "&lt;FILE&gt;": No such file or directory
  </code></pre>
  
  <p>After some experimenting I found that removing the escaped single quotes fixed the 2nd issue. The working line looks like this:</p>
  
  <pre><code>FILE_EXISTS=$(ssh "$SERVER" find "$MYPATH" -name \""$FILE"\")
  </code></pre>