David Z
David Z

Reputation: 7041

for loop in bash with multiple arrays

What I'm trying to do is like this:

for i in {{1..3}, {25..27}}
do
 echo $i
done

but it gives:

{1,
{2,
{3,
25}
26}
27}

I'm wondering how I can get a return as this:

1
2
3
25
26
27

Upvotes: 1

Views: 250

Answers (2)

Etan Reisner
Etan Reisner

Reputation: 80921

Two ways. Drop the space after the comma or drop the entire outer brace expansion as unnecessary.

$ for i in {{1..3},{25..27}}
do
 echo $i
done

or

$ for i in {1..3} {25..27}
do
 echo $i
done

Upvotes: 5

anubhava
anubhava

Reputation: 784928

Don't nest { and } and use it as:

for i in {1..3} {25..27}; do  echo $i; done
1
2
3
25
26
27

Upvotes: 3

Related Questions