title: How to execute commands read from the txt file using shell?
body: <p>I tried to execute commands read it from txt file. But only 1st command is executing, after that script is terminated. My script file name is shellEx.sh is follows:</p>
  
  <pre><code>echo "pwd" &gt; temp.txt
  echo "ls" &gt;&gt; temp.txt
  exec &lt; temp.txt
  while read line
  do
  exec $line
  done
  echo "printed"
  </code></pre>
  
  <p>if I keep echo in the place of exec, just it prints both pwd and ls. But i want to execute pwd and ls one by one.</p>
  
  <p>o/p am getting is:</p>
  
  <pre><code>$ bash shellEx.sh
  /c/Users/Aditya Gudipati/Desktop
  </code></pre>
  
  <p>But after pwd, ls also need to execute for me.
  Anyone can please give better solution for this?</p>