1

I'm trying to use the output of this in a for loop:

$wc -l example.mgn | awk '{print $1}'
12

however, I get this:

for i in {1..`wc -l example.mgn | awk '{print $1}'`}; do echo $i; done
{1..12}
Bob
  • 10,741
  • 27
  • 89
  • 143

1 Answers1

0

Brace expansion occurs before any other type of expansion, you can only include literal values in braces. For example, {1..12} is valid, but you can't replace either 1 or 12 with a command that produces a number.

Instead, use

for ((i=1; i<= $(wc -l < example.mgn); i++)); do
    echo "$i"
done
chepner
  • 497,756
  • 71
  • 530
  • 681