Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Don't use <code>eval</code> ever, except maybe if there is no other way AND you really know what you are doing.</p> <p>The <code>STATD$counter=$(...)</code> should give an error. That's not a valid assignment because the string "<code>STATD$counter</code>" is not a valid variable name. What will happen is (using a concrete example, if counter happened to be 3 and your pipeline in the <code>$( )</code> output "output", bash will only expand that line as far as "<code>STATD3=output</code>" so it will try to find a command named "<code>STATD3=output</code>" and run it. Odds are this is not what you intended.</p> <p>It sounds like everything you want to do can be accomplished with arrays instead. If you are not familiar with bash arrays take a look at <a href="http://mywiki.wooledge.org/BashGuide" rel="nofollow">Greg's Wiki</a>, in particular <a href="http://mywiki.wooledge.org/BashFAQ/005" rel="nofollow">this page</a> or the bash man page to find out how to use them.</p> <p>For example, in the loop you didn't post in your question: make <code>disk</code> (not <code>DISK</code>: <a href="http://mywiki.wooledge.org/BashSheet?highlight=%28uppercase%29#Parameters" rel="nofollow" title="In the naming conventions of bash, all uppercase variable names are reserved for shell internal variables (like HOME, BASH, PATH, MAIL, etc).">don't use all upper case variable names</a>) an array like so</p> <pre><code>disk+=( "new value" ) </code></pre> <p>or even</p> <pre><code>disk[counter]="new value" </code></pre> <p>Then in the loop in your question, you can make <code>statd</code> an array as well and assign it with values from disk by</p> <pre><code>statd[counter]="... ${disk[counter]} ..." </code></pre> <p>It's worth saying again: avoid using <code>eval</code>. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload