Linked Questions

109 votes
3 answers
154k views

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 ...
Classified's user avatar
  • 6,100
73 votes
7 answers
110k views

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})
Tyilo's user avatar
  • 30.4k
40 votes
7 answers
25k views

#!/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! ...
user avatar
79 votes
1 answer
186k views

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 ...
sodiumnitrate's user avatar
6 votes
2 answers
17k views

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 ...
wiswit's user avatar
  • 6,025
6 votes
4 answers
10k views

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: ...
pogibas's user avatar
  • 28.5k
3 votes
1 answer
5k views

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 ...
JawguyChooser's user avatar
1 vote
6 answers
4k views

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 $...
Linguist's user avatar
  • 123
0 votes
1 answer
2k views

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? ...
Michal Vician's user avatar
2 votes
3 answers
426 views

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 ...
Zak's user avatar
  • 25.3k
1 vote
2 answers
2k views

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 ...
derek's user avatar
  • 11
3 votes
2 answers
286 views

How can I use variable in for loop digits? for example: num="12" for i in {0..$num}; do ... done
rabotalius's user avatar
  • 1,578
-1 votes
3 answers
1k views

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 ...
nbx's user avatar
  • 1
0 votes
1 answer
1k views

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?...
cauthon14's user avatar
  • 296
0 votes
1 answer
669 views

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
M_Zakaria's user avatar

15 30 50 per page
1
2 3 4 5
8