Linked Questions
107 questions linked to/from How do I iterate over a range of numbers defined by variables in Bash?
109 votes
3 answers
154k views
How to use variables in a bash for loop [duplicate]
How does one use a variable in a bash for loop? If I just use a standard for loop, it does what I expect for i in {0..3} do echo "do some stuff $i" done This works fine. It loops thru 4 times, 0 ...
73 votes
7 answers
110k views
Variables in bash seq replacement ({1..10}) [duplicate]
Is it possible to do something like this: start=1 end=10 echo {$start..$end} # Ouput: {1..10} # Expected: 1 2 3 ... 10 (echo {1..10})
40 votes
7 answers
25k views
Brace expansion with variable? [duplicate]
#!/bin/sh for i in {1..5} do echo "Welcome" done Would work, displays Welcome 5 times. #!/bin/sh howmany=`grep -c $1 /root/file` for i in {1..$howmany} do echo "Welcome" done Doesn't work! ...
79 votes
1 answer
186k views
bash for loop: a range of numbers [duplicate]
I have the following code in an .sh file: for num in {1..10} do echo $num done Which should print numbers from 1 to 10. But, this is what I get: {1..10} Also, using C-like sytax doesn't work ...
6 votes
2 answers
17k views
How to generate for loop number sequence by using variable names in bash? [duplicate]
Could anybody explain how can I use variable names in bash for loop to generate a sequence of numbers? for year in {1990..1997} do echo ${year} done Results: 1990 1991 1992 1993 1994 1995 1996 ...
6 votes
4 answers
10k views
Bash for loop - naming after n (which is user's input) [duplicate]
I am looping over the commands with for i in {1..n} loop and want output files to have n extension. For example: for i in {1..2} do cat FILE > ${i}_output done However n is user's input: ...
3 votes
1 answer
5k views
bash variable for upper limit of for loop number syntax [duplicate]
If I create a bash loop like this, using literal numbers, all works as expected: #!/bin/bash for i in {1..10}; do echo $i done The output is: 1 2 3 4 5 6 7 8 9 10 But if I want to use the upper ...
1 vote
6 answers
4k views
Evaluate expression inside bash for loop [duplicate]
If I do this, I get the result as expected. for i in {125..129}; do echo $i; done 125 126 127 128 129 But when I do this? I get something weired. for i in {$((1+(25-1)*500))..$((25*500))}; do echo $...
0 votes
1 answer
2k views
Bash foreach loop works differently when executed from .sh file [duplicate]
The following 'oneliner' does what I need: $ for i in {1..5}; do echo $i; done 1 2 3 4 5 However, when I place exactly the same code into for-each.sh file and execute it, I get different result. Why? ...
2 votes
3 answers
426 views
bash for loop question [duplicate]
Possible Duplicate: How do I iterate over a range of numbers in bash? When I do this: RANGE_COUNT=28 for i in {0..$RANGE_COUNT} ; do echo $i; done I get this {0..28} When I do this: for i ...
1 vote
2 answers
2k views
Possible to expand Bash variable in curly braces? [duplicate]
In BASH, is it possible to expand a variable in a brace expansion? For instance, if one would like to obtain a printed sequence 1 to 10, they could do: echo {1..10} let's say that instead of 10, I ...
3 votes
2 answers
286 views
Variable in for loop digits [duplicate]
How can I use variable in for loop digits? for example: num="12" for i in {0..$num}; do ... done
-1 votes
3 answers
1k views
bash script. run command with counted numbers and names [duplicate]
i try to code a script. it ask me how many "anything" you want? and i answered with a number like 10 #!/bin/bash echo -n "Please enter some input: " read input now I like perform a command 10 times ...
0 votes
1 answer
1k views
Create an array in bash from given start and end point [duplicate]
I have this code that works: $ array=( {100..300..100} ) $ for k in ${array[@]} ; do echo $k ; done 100 200 300 I want to parametrize the start and end points (and also the increment, because why not?...
0 votes
1 answer
669 views
how to assign variable value in this touch command [duplicate]
first i want to read number of files that he want to create it #!/bin/bash touch file{0..$number} I trayed with this syntax but output is the following file{0..number} >> as example