2

I am uncertain on how to correctly all a variable in a for loop. I have currently set a variable equal to the total number of lines in a file and want to use it in a for loop that will run a set of code.

I tried the following:

variable=$(awk 'END { print NR }' file)

I want to use this variable in a for loop, here is a simple example:

for i in {1..$variable}; do

     print ${i}

done

This doesn't work as I think I have called the variable incorrectly.

Any help would be greatly appreciated. Thank you.

Rish
  • 794
  • 1
  • 6
  • 14
  • `{n..m}` cannot use variables because the brace expansion is performed before the variables are evaluated. So to do this you need to use `seq`. – fedorqui Jul 18 '15 at 17:50

0 Answers0