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

时间:2014-09-11 20:21:24

标签: bash permissions .bash-profile enscript

通过this post,我使用以下命令将目录中递归的所有.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

有什么想法吗?感谢。

1 个答案:

答案 0 :(得分:2)

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

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

使用你所拥有的,别名如下:

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

其中说明了所有权限被拒绝的错误来自哪里。