title: Bash script doesn't exit SSH host after execution
body: <p>I am running a CentOS 7 VM that I want to set a static IP to.</p>
  
  <p>Running <code>SSHPASS=password sshpass -e ssh -tt -o "StrictHostKeyChecking no" host@192.168.122.229 'echo "password" | sudo -Sv &amp;&amp; bash -s' &lt; script.sh</code> executes all the commands in <code>script.sh</code> but, after completion, the terminal stays inside the VM, irregardless of whether I have the <code>exit</code> command at the end of my bash script or not.</p>
  
  <p>The reason for piping my password is to skip entering it in the terminal.</p>
  
  <p>Here is my bash script:</p>
  
  <pre><code>sudo cp /etc/sysconfig/network-scripts/ifcfg-ens3  /etc/sysconfig/network-scripts/ifcfg-ens3:0
  sudo sed -i 's/BOOTPROTO="dhcp"/BOOTPROTO="static"/g' /etc/sysconfig/network-scripts/ifcfg-ens3:0
  sudo sed -i 's/NAME="ens3"/NAME="ens3:0"/g' /etc/sysconfig/network-scripts/ifcfg-ens3:0
  sudo sed -i 's/DEVICE="ens3"/DEVICE="ens3:0"/g' /etc/sysconfig/network-scripts/ifcfg-ens3:0
  echo 'PEERDNS="yes"' | sudo tee -a /etc/sysconfig/network-scripts/ifcfg-ens3:0
  echo 'IPADDR=192.168.122.201' | sudo tee -a /etc/sysconfig/network-scripts/ifcfg-ens3:0
  echo 'NETMASK=255.255.255.0' | sudo tee -a /etc/sysconfig/network-scripts/ifcfg-ens3:0
  echo 'GATEWAY=192.168.122.1' | sudo tee -a /etc/sysconfig/network-scripts/ifcfg-ens3:0
  sudo systemctl restart network
  exit
  </code></pre>
  
  <p>Ideally, I would like to execute these commands in the same script but I can't seem to figure out what the problem is.</p>
  
  <p>Interesting note: if I run <code>cat script.sh | SSHPASS=password sshpass -e ssh -tt host@192.168.122.229 'echo "password" | sudo -Sv &amp;&amp; bash -s'</code> the console stops on the <code>exit</code> command (not inputted) and if I press enter to input it, the VM stalls and I can only exit with CTRL+C.</p>
  
  <p>UPDATE
  If I run <code>./script.sh</code> that has the following contents...</p>
  
  <pre><code>ssh -tt host@192.168.122.229 'echo "password" | sudo -Sv &amp;&amp; bash -s' &lt;&lt; EOF
  echo
  sudo cp /etc/sysconfig/network-scripts/ifcfg-ens3  /etc/sysconfig/network-scripts/ifcfg-ens3:0
  sudo sed -i 's/BOOTPROTO="dhcp"/BOOTPROTO="static"/g' /etc/sysconfig/network-scripts/ifcfg-ens3:0
  sudo sed -i 's/NAME="ens3"/NAME="ens3:0"/g' /etc/sysconfig/network-scripts/ifcfg-ens3:0
  sudo sed -i 's/DEVICE="ens3"/DEVICE="ens3:0"/g' /etc/sysconfig/network-scripts/ifcfg-ens3:0
  echo 'PEERDNS="yes"' | sudo tee -a /etc/sysconfig/network-scripts/ifcfg-ens3:0
  echo 'IPADDR=192.168.122.201' | sudo tee -a /etc/sysconfig/network-scripts/ifcfg-ens3:0
  echo 'NETMASK=255.255.255.0' | sudo tee -a /etc/sysconfig/network-scripts/ifcfg-ens3:0
  echo 'GATEWAY=192.168.122.1' | sudo tee -a /etc/sysconfig/network-scripts/ifcfg-ens3:0
  exit
  EOF
  </code></pre>
  
  <p>Everything works. Which leads me to believe that the problem is related to <code>sudo systemctl restart network</code>. Confirmed by adding <code>sudo systemctl restart network; exit</code> at the end of the script. Maybe it has something to do with the nature of this command.</p>