title: "command not found" errors in expect script executed by shell script
body: <p>I am trying to implement "shell script calling expect script" so that it does not prompt the user for entering ssh password every time. I started with <a href="https://stackoverflow.com/questions/4594698/using-a-variables-value-as-password-for-scp-ssh-etc-instead-of-prompting-for-u">Using a variable&#39;s value as password for scp, ssh etc. instead of prompting for user input every time</a> and understood that I should have a <code>.sh</code> file and a <code>.exp</code> file. I have <code>expect</code> installed in my system (running <code>expect -v</code> shows <code>expect version 5.43.0</code>). </p>
  
  <p>In my <code>upload-to-server.sh</code> file I have </p>
  
  <pre><code>cd $SOURCE_PATH/shell
  ./password.exp $DESTINATION_PATH $SSH_CREDENTIALS $PROJECT_INSTALLATION_PATH $PASSWORD
  </code></pre>
  
  <p>And in my <code>password.exp</code> file I have </p>
  
  <pre><code>#!/usr/bin/expect -f
  
  set DESTINATION_PATH [lindex $argv 0];
  set SSH_CREDENTIALS [lindex $argv 1];
  set PROJECT_INSTALLATION_PATH [lindex $argv 2];
  set PASSWORD [lindex $argv 3];
  
  spawn scp $DESTINATION_PATH/exam.tar $SSH_CREDENTIALS':/'$PROJECT_INSTALLATION_PATH
  expect "password:"
  send $PASSWORD"\n";
  interact
  </code></pre>
  
  <p>On running the <code>upload-to-server.sh</code> file I get the following error - </p>
  
  <pre><code>./password.exp: line 9: spawn: command not found
  couldn't read file "password:": no such file or directory
  ./password.exp: line 11: send: command not found
  ./password.exp: line 12: interact: command not found
  </code></pre>
  
  <p>I arrived at the above code (in the exp file) from multiple sources (without understanding much basics). In <a href="https://stackoverflow.com/questions/459182/using-expect-to-pass-a-password-to-ssh">one source</a> the code is like this </p>
  
  <pre><code>#!/usr/local/bin/expect
  spawn  sftp  -b cmdFile user@yourserver.com
  expect "password:"
  send "shhh!\n";
  interact
  </code></pre>
  
  <p>Whereas in <a href="https://stackoverflow.com/questions/2242643/how-to-use-a-shell-script-to-supply-a-password-when-the-interface-asks-for-it">another source</a> like this </p>
  
  <pre><code>#!/usr/local/bin/expect -f
  set TESTCASE_HOME [lindex $argv 0];
  set TESTCASE_LIST [lindex $argv 1];
  set PASSWORD [lindex $argv 3];
  
  set timeout 200
  spawn $TESTCASE_HOME/dobrt -p $TESTCASE_HOME/$TESTCASE_LIST
  expect "*?assword:*" {send -- "$PASSWORD\r";}
  expect eof
  </code></pre>
  
  <p>There are some differences there - </p>
  
  <ul>
  <li>there is an extra <code>-f</code> in the <code>#!/usr/local/bin/expect</code> line</li>
  <li><p>expect "<em>?assword:</em>" {send -- "$PASSWORD\r";} is different from <code>expect "password:"
  send "shhh!\n";</code></p></li>
  <li><p><code>interact</code> replaced with <code>expect eof</code>.</p></li>
  </ul>
  
  <p>This is my first <code>expect script</code> so don't have much idea what to code. Any pointers?</p>
  
  <p>Thanks,<br>
  Sandeepan</p>