Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make one line for loop in android shell

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}

like image 345
xdan Avatar asked Mar 12 '14 06:03

xdan


People also ask

How do you put a loop in a shell script?

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.

Can we use for loop in shell script?

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.

Can you do a loop in bash?

We can use loops and conditional statements in BASH scripts to perform some repetitive and tricky problems in a simple programmatic way.

How do you write an infinite loop in shell script?

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.


2 Answers

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
like image 144
Sahil Mahajan Mj Avatar answered Oct 10 '22 18:10

Sahil Mahajan Mj


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
like image 36
scottt Avatar answered Oct 10 '22 17:10

scottt