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. vd
is an executable on this server that prints data. Here I have arguments to print 5 lines of data -n5
from a specific sensor -s ${scylpres[n]}
, then filter the output so it only prints lines with the "," delimiter cut -d',' -s -f1-
.
scylpres=($(eproms | grep -i 'trtl' | grep -i 'cylinder pressure' | cut -d',' -f3));
alias cylpres='vd -n5 -s ${scylpres[0]} | cut -d',' -s -f1- &&
vd -n5 -s ${scylpres[1]} | cut -d',' -s -f1- && vd -n5 -s ${scylpres[2]} | cut -d',' -s -f1- && vd -n5 -s ${scylpres[3]} | cut -d',' -s -f1- &&
vd -n5 -s ${scylpres[4]} | cut -d',' -s -f1- && vd -n5 -s ${scylpres[5]} | cut -d, -s -f1-';
I am struggling to wrap this into a for loop. I've tried:
i=0;
function cpres {
for i in {0..${scylpres[@]}}
do
vd -n5 -s ${scylpres${i}} | cut -d',' -s -f1-
done
};
And:
start=0;
stop=${scylpres[@]};
function cpres {
for((i=$start;i<=$end;i++))
do
vd -n5 -s ${scylpres[$((i++))]} | cut -d',' -s -f1-
done
};
And have tried different versions of the i call in both of these. For example, ${scylpres[$i]}
,${scylpres[$(i)]}
, ${scylpres$[((i++))]}
But, all I'm seeing is my command line go to >
.