我在 perl 文件中有以下代码。该命令的目的是在file.txt的末尾添加一行“--test 0”。
system(" find . -type f -name file.txt | xargs sed -i -e "$ a- - test 0" ");
当我尝试运行脚本时,出现如下错误。
Scalar found where operator expected at timeStampConfig.pl line 24, near "" find . -type f -name file.txt | xargs sed -i -e "$ a"
(Missing operator before $ a?)
Number found where operator expected at timeStampConfig.pl line 24, near "test 0"
(Do you need to predeclare test?)
String found where operator expected at timeStampConfig.pl line 24, near "0" ""
(Missing operator before " "?)
syntax error at timeStampConfig.pl line 24, near "" find . -type f -name file.txt | xargs sed -i -e "$ a"
Execution of timeStampConfig.pl aborted due to compilation errors.
我尝试从命令提示符执行以下行,效果很好。
find . -type f -name file.txt | xargs sed -i -e '$ a- - test 0'
我还尝试使用单引号,如下所示,但最终出现错误。
system("find . -type f -name file.txt | xargs sed -i -e '$ a- - test 0'");
sed: -e expression #1, char 1: unknown command: `-'
我是 Perl 新手,需要一些帮助。