title: Run commands from a text file through a bash script
body: <p>I am attempting to write a script that will read through a text file, and then execute every line that begins with the word "run" or "chk" as a command. This is what I have thus far:</p>
  
  <pre><code>#!/bin/bash
  counter=1
  for i in $@
  do
      while read -r line 
      do
      if [[ ${line:0:4} == "run " ]]
      then
          echo "Now running line $counter" 
          ${line:4:${#line}}
      elif [[ ${line:0:4} == "chk " ]]
      then
          echo "Now checking line $counter" 
          ${line:4:${#line}}
      elif [[ ${line:0:2} == "# " ]]
      then
          echo "Line $counter is a comment"
      else
          echo "Line $counter: '$line' is an invalid line"
      fi
      counter=$((counter+1))
      done&lt;$i
  done
  </code></pre>
  
  <p>However, when I feed it a text file with, for example the commands</p>
  
  <pre><code>run echo &gt; temp.txt
  </code></pre>
  
  <p>It does not actually create a file called temp.txt, it just echoes "> temp.txt" back to the stdout. It also does a similar thing when I attempt to do something like </p>
  
  <pre><code>run program arguments &gt; filename.txt
  </code></pre>
  
  <p>It does not put the output of the program in a file as I want, but it rather tries to treat the '>' as a file name. </p>
  
  <p>I know this is a super specific and probably obvious thing, but I am very new to bash and all shell scripting.</p>
  
  <p>Thanks</p>