Change User from bash script
<p>I have a user "chad"</p>

<p>I am logging into linux machine with user "server"</p>

<p>I am creating a script and try to add below command</p>

<pre><code> sudo su -s /bin/bash chad
</code></pre>

<p>so I can get into user chad and execute rest of my commands from this script
How do I do that?</p>

<p>Below Is My script</p>

<pre><code>   #!/bin/bash

   exec /bin/su -s /bin/bash chad - &lt;&lt; 'EOF'

   echo "pwd"
   pwd

   cd /home/chad/py2.0/test/py_it/


   echo "git branch"
   git branch



   read -p "Are you sure about branch? (yes/no)" reply

   choice=$(echo $reply|sed 's/\(.*\)/\L\1/')

   if [ "$choice" = 'yes' ] 
   then
   echo "Welcome you selected yes, wait for 3 seconds to get output";
   sleep 3;
   echo "git pull for py2.0";
   "git pull origin integration/py2.0";

   elif [ "$choice" = 'no'  ]
   then

   echo "You selected 'no', hence exiting in 3 seconds";
   sleep 3
   exit 0
   else
   echo "invalid answer, type yes or no";
   fi
   EOF
</code></pre>

<p>Below is Output</p>

<pre><code>   git branch
  * integration/py2.0
   master
  invalid answer, type yes or no
</code></pre>