1

I want to print all the integer value from 1 to 10 by using echo {1..$num} and i want to used it pdftk

If i do with echo {1..10} it is printing what i exactly want, but i want to pass a value to some variable and that variable below is my MWE.

  #!/bin/bash
  num=10
  echo {1..10} # This code printing correctly
  echo {1..$num} # This code not printing correctly
  pdftk {1..$num}.pdf cat output final.pdf

but it is prininting 1..10 only but i want to print 1 2 3 4 5 6 7 8 9 10

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Biki Teron
  • 237
  • 2
  • 4
  • 12

1 Answers1

1

Brace expansion is performed before parameter expansion. Therefore your approach does not work. You could do instead a

num=10
seq $num
for n in $(seq $num)
do
  pdftk $n.pdf
done 

If you want to avoid a loop, do instead a

pdftk $(seq $num | sed 's/$/.pdf/')

or

pdftk $(printf "%s.pdf " $(seq $num))

instead.

user1934428
  • 19,864
  • 7
  • 42
  • 87