title: Bash reading value from a file to set a variable
body: <p>I'm trying to clean up some of my code to remove a lot of my repeated code for running tests and monitoring logs through soft and hard reboots.</p>
  <p>The script I have will cycle through 7 sets of tests and output the results to their each respective folders in the /persist/ directory. I have a file which contains nothing but an integer of 1-7 to record which stage of testing I am on (has to persist through reboots) in</p>
  <pre><code>/persist/whichtest
  </code></pre>
  <p>The below tests/folders are located in <code>/persist/</code> for my results to go into</p>
  <pre><code>Boot
  stress
  swap
  longevity
  gps
  platform
  gpslong
  </code></pre>
  <p>How would i go about setting &quot;${testname[i]}&quot; to equal one of my test names depending on the number set in <code>/persist/whichtest</code>?</p>
  <p>So each time it performs the tests in <code>Boot</code>, it will output the results to <code>/persist/Boot</code> and when the tests of <code>gps</code> are being performed, the results will go to <code>/persist/gps</code></p>
  <pre><code>function logs {
    echo &quot;insertlog stuff here&quot; &gt;&gt; /persist/&quot;${testname[i]}&quot;/test1.log
    echo &quot;insertlog stuff here&quot; &gt;&gt; /persist/&quot;${testname[i]}&quot;/test2.log
    echo &quot;insertlog stuff here&quot; &gt;&gt; /persist/&quot;${testname[i]}&quot;/test3.log
  }
  </code></pre>
  <pre><code>declare -a testname=(Boot stress swap longevity gps platform gpslong)
  </code></pre>
  <p>When it is running the first round of tests, the results will go into <code>/persist/Boot/</code></p>
  <p>When it is running second round of tests, the results will go into <code>/persist/stress/</code></p>
  <p>Then to follow the same pattern for each test case</p>
  <p>This is the function I was looking to use</p>
  <pre><code>function errorlog {
          echo &quot;&quot; &quot;$(date)&quot; | tee -a /persist/&quot;${testname[i]}&quot;/error.log
          /bin/dmesg | grep -i &quot;seg\|error\|fault\|unified\|qmi&quot; &gt;&gt; /persist/&quot;${testname[i]}&quot;/error.log
          grep -i &quot;seg\|error\|fault\|unified\|qmi&quot; &gt;&gt; /persist/&quot;${testname[i]}&quot;/error.log
  }
  </code></pre>
  <p>I've hit a bit of a wall so any advice is appreciated.</p>
  <p>Edited my original question, sorry it wasn't very well worded. Hopefully this will make things more clear.</p>
  <p><a href="https://pastebin.com/GLUTDrRk" rel="nofollow noreferrer">Full script is here</a></p>