Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The command

pdftk FileOne.pdf "File two.pdf" output Combined.pdf  

works as expected, merging PDF's One and Two. However, if I put the filenames in a file

"File Two.pdf"  

and then use

pdftk $(< Files.lst) output Combined.pdf  

I get the error messages

Error: Failed to open PDF file: 
Error: Unable to find file.
Error: Failed to open PDF file: 

Obviously, pdftk is seeing the quotes, so I don't understand how it can distinguish the two cases (which is why I am posing the question in this forum).

For the record, I am using MKS Toolkit Korn shell, invoked from Emacs. I get the same in the Cygwin bash shell.

share|improve this question

Write the file as:

File Two.pdf

And use as:

set -f
' # split on newline only
pdftk $(< Files.lst) output Combined.pdf
share|improve this answer

You have two problems (at least).

The first is you need to read your source file (Files.list) one line at at time. You can probably do this more then one way, but one way is with read

See : http://stackoverflow.com/questions/10929453/bash-scripting-read-file-line-by-line

Second is due to the spaces in your file names (resulting in the error "Failed to open PDF file: Two.pdf" ). You need to either quote your variables or escape the space.

so any of the following works with spaces in the file name,

echo "$variable"
cat "File with spaces.txt" 
cat 'File 2.txt'
cat File\ 3\ with\ spaces.txt

There is an elegant solution here:


share|improve this answer

You can remove the quotes from the text file, and read it into an array with bash's mapfile:

mapfile -t files < Files.lst
pdftk "${files[@]}" output Combined.pdf  
share|improve this answer
This would be a good answer if the question didn't specifically mention the use of a shell other than bash. – Gilles Dec 14 '13 at 22:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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