Answer the question
In order to leave comments, you need to log in
How to organize dynamic use of for?
It is necessary to go through all the elements of the array with a step of 2, but the number of elements is not known in advance.
more or less like this:
#!/bin/bash
arr=([1]=1 [2]=2 3 [5]=4 5);
for i in {0..${#arr[*]}..2};do
printf "[$i]:${arr[$i]}\n";
done
arr.sh: line 4: {0..5..2}: syntax error: expected operand (wrong label "{0..5..2}")
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question