perl -le inside parens并没有在bash脚本中工作

时间:2016-04-19 14:57:56

标签: bash perl

我使用脚本使用perl命令从文本文件运行内容。它在括号内,显示未找到的命令。我试图将这一行包含在一个变量中并通过$()或$ {variable}执行,但返回总是"(:找不到命令"

#!/bin/bash
...
( perl -le 'print "test"' && cat example.txt) > example2.txt || ( rm -rf example2.txt && false )

1 个答案:

答案 0 :(得分:2)

您发布的代码未显示您声明的行为。

$ cat a.bash
#!/bin/bash
( perl -le 'print "test" && cat example.txt) > example2.txt || ( rm -rf example2.txt && false )

$ ./a.bash
./a.bash: line 2: unexpected EOF while looking for matching `''
./a.bash: line 3: syntax error: unexpected end of file

$

添加缺失的'后:

$ cat a.bash
#!/bin/bash
( perl -le 'print "test"' && cat example.txt) > example2.txt || ( rm -rf example2.txt && false )

$ ./a.bash

$