I have a bash script with a line that was originally this

convert '%d.jpg[1-300]' combined.pdf

Uses convert from Imagemagick to strap a load of sequentially numbered jpgs in to a PDF.

I've written a basic script to accept user input for a changeable number of pages and tried to swap the 300 for a variable set by the user when the script runs using read -p to make this:

convert '%d.jpg[1-$pages]' combined.pdf

The rest of the script works fine but it fails on this line and I'm not sure why. Any suggestions?

I suspect its something to do with incorrect delimiters but I don't know the correct thing to look for.

New contributor
Big_James is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

1 Answer 1


Parameter expansion is not performed inside single-quotes. It is performed inside double quotes though, so:

convert "%d.jpg[1-$pages]" combined.pdf

In any case, you need some form of quoting as [ is special in most shells as a glob operator (fish being a notable exception, but in fish (older versions anyway) it's % that's special), and in all Bourne-like shells except zsh, unquoted parameter expansion is subject to split+glob which we don't want here.

  • That appears to have got it. Thank you for enlightening me as to what filename globbing and glob operators are and do. Same for parameter expansion.
    – Big_James
    Mar 18 at 23:07

Your Answer

Big_James is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.