There are two ways to iterate over items of array using For loop. The first way is to use the syntax of For loop where the For loop iterates for each element in the array. The second way is to use the For loop that iterates from index=0 to index=array length and access the array element using index in each iteration.
Using shorthand operators is the simplest way to append an element at the end of an array. In the following script, an array with 6 elements is declared. Next '+=' shorthand operator is used to insert a new element at the end of the array. 'for' loop is used here to iterate the array and print the array elements.
There is no do-while loop in bash. To execute a command first then run the loop, you must either execute the command once before the loop or use an infinite loop with a break condition.
However, BASH lacks the ability to return arrays from functions.
I would like to fill an array automatically in bash like this one:
200 205 210 215 220 225 ... 4800
I tried with for like this:
for i in $(seq 200 5 4800);do
array[$i-200]=$i;
done
Can you please help me?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With