Linux for loop function in .bashrc
<p>I have the following alias set up in ~/.bashrc. It prints data from some sensors connected to a server. I'd like to condense this into a for loop, but cannot get the loop to run successfully. The non-loop syntax I have working is below. <code>vd</code> is an executable on this server that prints data. Here I have arguments to print 5 lines of data <code>-n5</code> from a specific sensor <code>-s ${scylpres[n]}</code>, then filter the output so it only prints lines with the "," delimiter <code>cut -d',' -s -f1-</code>. </p>

<pre><code>scylpres=($(eproms | grep -i 'trtl' | grep -i 'cylinder pressure' | cut -d',' -f3));
alias cylpres='vd -n5 -s ${scylpres[0]} | cut -d',' -s -f1- &amp;&amp;
vd -n5 -s ${scylpres[1]} | cut -d',' -s -f1- &amp;&amp; vd -n5 -s ${scylpres[2]} | cut -d',' -s -f1- &amp;&amp; vd -n5 -s ${scylpres[3]} | cut -d',' -s -f1- &amp;&amp;
vd -n5 -s ${scylpres[4]} | cut -d',' -s -f1- &amp;&amp; vd -n5 -s ${scylpres[5]} | cut -d, -s -f1-';
</code></pre>

<p>I am struggling to wrap this into a for loop. I've tried:</p>

<pre><code>i=0;
function cpres {
for i in {0..${scylpres[@]}}
do
vd -n5 -s ${scylpres${i}} | cut -d',' -s -f1-
done
};
</code></pre>

<p>And: </p>

<pre><code>start=0;
stop=${scylpres[@]};
function cpres {
for((i=$start;i&lt;=$end;i++))
do
vd -n5 -s ${scylpres[$((i++))]} | cut -d',' -s -f1-
done
};
</code></pre>

<p>And have tried different versions of the i call in both of these. For example, <code>${scylpres[$i]}</code>,<code>${scylpres[$(i)]}</code>, <code>${scylpres$[((i++))]}</code>
But, all I'm seeing is my command line go to <code>&gt;</code> .  </p>