我使用脚本使用perl命令从文本文件运行内容。它在括号内,显示未找到的命令。我试图将这一行包含在一个变量中并通过$()或$ {variable}执行,但返回总是"(:找不到命令"
#!/bin/bash
...
( perl -le 'print "test"' && cat example.txt) > example2.txt || ( rm -rf example2.txt && false )
答案 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
$