在bash_profile中添加enscript命令作为别名时,权限被拒绝



通过这篇文章,我使用以下命令将目录中的所有.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

有什么想法吗?谢谢

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

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

根据您所拥有的,别名看起来像:

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

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

相关内容

  • 没有找到相关文章

最新更新