This works on bash
for i in {1..5}; do echo $i; done
the out put is 1 2 3 4 5 But on android shell the output is {1..5}
The basic syntax of a for loop is: for <variable name> in <a list of items>;do <some command> $<variable name>;done; The variable name will be the variable you specify in the do section and will contain the item in the loop that you're on.
A for loop is classified as an iteration statement i.e. it is the repetition of a process within a bash script. For example, you can run UNIX command or task 5 times or read and process list of files using a for loop. A for loop can be used at a shell prompt or within a shell script itself.
We can use loops and conditional statements in BASH scripts to perform some repetitive and tricky problems in a simple programmatic way.
The following syntax is used for create infinite while loop in a shell script. echo "Press [CTRL+C] to exit this loop..." You can also Unix true command with while loop to run it endlessly. The while loop syntax with true command will look like below example.
Have you tried,
for ((i=1; i<=5; i++)) do echo $i; done
Edit-
or you can use sequence,
for i in `seq 1 5`; do echo $i; done
If your sequence isn't too large, you can just list out the values of interest. So in the default Android ADB shell:
for i in 1 2 3; do echo $i; done
Returns:
1
2
3
or:
for i in 5 11 7; do echo $i; done
Returns:
5
11
7
or even:
for i in apple orange banana; do echo $i; done
Returns:
apple
orange
banana
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