Search code examples
bashfor-loopbrace-expansion

use multiple variable with brace expression in for loop


This works fine :-

for i in host{1..4} host2{1..4}
do
    echo $i
done

Now,

I have two variable likes this :-

host=host{1..4}

host2=host2{1..4}

how do i use this two variable in above loop so both work same?

something like this :-

for i in $host $host2
do
    echo $i
done

any help is appriciated


Solution

  • use eval:

    $ for i in `eval echo $host $host2`;do echo $i;done
    host1
    host2
    host3
    host4
    host21
    host22
    host23
    host24