2

通过这篇文章,我使用以下命令将目录中的所有 .java 文件递归导出为 PDF 格式(files.pdf):

enscript -r -1 --file-align=2 --font=Courier7 --pretty-print=java --line-numbers -o - `find . -name '*.java'` | ps2pdf - files.pdf

这工作正常。但是,当我将以下行添加到我的bash_profile

alias printJavaFiles="enscript -r -1 --file-align=2 --font=Courier7 --pretty-print=java --line-numbers -o - `find . -name '*.java'` | ps2pdf - files.pdf"

和来源bash_profile,运行printJavaFiles给我一个权限被拒绝错误,我试图打印的每个 .java 文件,如下所示:

bash: ./datastructuretradeoffs/Main.java: Permission denied
bash: ./graphs/Main.java: Permission denied
bash: ./linkedlists/ListNode.java: Permission denied
bash: ./linkedlists/Main.java: Permission denied
bash: ./recursion/Main.java: Permission denied
bash: ./sorting/BinarySearch.java: Permission denied
bash: ./sorting/MergeSort.java: Permission denied
bash: ./stacksqueues/Main.java: Permission denied
bash: ./stacksqueues/MyQueue.java: Permission denied
bash: ./stacksqueues/Node.java: Permission denied
bash: ./stacksqueues/Queue.java: Permission denied
bash: ./stacksqueues/SetOfStacks.java: Permission denied
bash: ./stacksqueues/Stack.java: Permission denied
bash: ./strings/Main.java: Permission denied
bash: ./trees/BinaryTree.java: Permission denied
bash: ./trees/BTreePrinter.java: Permission denied
bash: ./trees/ExampleTrees.java: Permission denied
bash: ./trees/Main.java: Permission denied
bash: ./trees/TreeNode.java: Permission denied

有任何想法吗?谢谢。

4

1 回答 1

3

因为在定义别名时使用了双引号,所以内部反引号会立即执行。使用单引号定义别名:

alias printJavaFiles='enscript ... -o - $(find . -name "*.java") | ps2pdf - files.pdf'
# changes ...........^..................^^.............^......^^.....................^

有了你所拥有的,别名看起来像:

alias printJavaFiles="enscript ... -o - ./a.java
./b.java
./c.java | ps2pdf - files.pdf"

这说明了所有权限被拒绝错误的来源。

于 2014-09-11T20:39:29.413 回答