Click here to Skip to main content
15,741,892 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi forum,

a bash script I wrote behaves unexpectedly (read: "There's a bug in it.") and I just don't get it.

Say there's that variable PAGES which contains " page0.pdf page1.pdf page2.pdf". And there is $1 which contains "result.pdf".

I want to merge all those single-page pdf files into one multi-page pdf file. There's pdfunite for that. The first line of the code snippet prints to the screen what the script is trying to execute, the second line does just that (or so I thought).
echo pdfunite "$PAGES" "$1"
pdfunite "$PAGES" "$1"
At that point, pdfunite prints its help message. Therefore I guess that something is wrong with the arguments I gave it.
But when I copy the output of the first line to the command prompt of the very terminal the script ran in, it pdfunites everything together perfectly.

So: Where's the difference in executing something (which does not work) to printing it to the console and copying it onto a new line to execute (which does work)?

What I have tried:

Printed the command in question to the console before actually executing it. And tried to execute the printed-out version (which actually works).
Richard MacCutchan 23-May-18 3:22am    
Try without the double quote characters.
lukeer 23-May-18 8:19am    
That works. Thank you very much.
Make that an answer and I'll upvote it as much as it gets.

May I ask if you know a rule behind when to use quotes and when not or what is causing this behaviour in this case?
Richard MacCutchan 23-May-18 9:27am    
That's OK, I don't need votes, a simple thank you is more than enough. I think you will find that when the file names are in quotes then the program will see them as a single string and not as three separate parameters. Type "man bash" at a terminal and you should find the explanation in the man page.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900