Bash escaping spaces in filename, in variable

旧巷老猫 提交于 2019-12-05 16:41:38

Putting multiple arguments into a single variable doesn't make sense. Instead, put them into an array:

args=(combined.pdf "my file.pdf");

Notice that "my file.pdf" is quoted to preserve whitespace.

You can use the array like this:

pdftk "${args[@]}" ...

This will pass two separate arguments to pdftk. The quotes in "${args[@]}" are required because they tell the shell to treat each array element as a separate "word" (i.e. do not split array elements, even if they contain whitespace).

As a side note, if you use bashisms like arrays, change your shebang to

#!/bin/bash

Try:

find test/*.pdf | xargs -I % pdftk % cat output all.pdf

As I said in my comments on other answers xargs is the most efficient way to do this.

EDIT: I did not see you needed a blank page but I suppose you could pipe the find above to some command to put the blank page between (similar to a list->string join). I prefer this way as its more FP like.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!