Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Perl脚本中使用Linux通配符_Linux_Perl_Append - Fatal编程技术网

在Perl脚本中使用Linux通配符

在Perl脚本中使用Linux通配符,linux,perl,append,Linux,Perl,Append,我有两个文件 ~/directory1/7120599_S1.txt hello world! ~/directory2/7120599_S7.txt bye world! hello world! bye world! 我正在寻找将7120599_S1.txt的内容附加到7120599_S7.txt末尾的Perl代码。以下命令在Linux中工作: $cat~/directory1/7120599_S1.txt>~/directory2/7120599_S*.txt 新~/director

我有两个文件

~/directory1/7120599_S1.txt

hello world!
~/directory2/7120599_S7.txt

bye world!
hello world!
bye world!
我正在寻找将
7120599_S1.txt
的内容附加到
7120599_S7.txt
末尾的Perl代码。以下命令在Linux中工作:

$cat~/directory1/7120599_S1.txt>~/directory2/7120599_S*.txt

新~/directory2/7120599_S7.txt

bye world!
hello world!
bye world!
但由于某些原因,这在Perl中不起作用

system "cat ~/directory1/7120599_S1.txt >> ~/directory2/7120599_S*.txt"
相反,它在
directory2
中创建一个名为
7120599_S*.txt
的新文件。如何让Perl识别Linux通配符?

如果我们看一下:

对于其他重定向运算符,重定向运算符后面的单词应进行波浪线扩展、参数扩展、命令替换、算术扩展和引号删除。非交互shell不应在word上执行路径名扩展;交互式shell可以执行此操作,但仅当扩展将导致一个单词时才应执行此操作

路径名扩展引用glob,如
*.txt

bashshell并不完全遵循POSIX,而是尝试更方便、更合理,包括对重定向目标应用路径名扩展,即使在非交互模式下也是如此。通常,交互式shell是Bash

但是,当您运行
system
命令时,这通常会运行一个更简单的shell,该shell与POSIX兼容(尽管这完全取决于您的操作系统)。此外壳通常作为
/bin/sh
安装

如果需要Bash,则必须显式运行Bash,例如

system "bash", "-c", "cat ~/directory1/7120599_S1.txt >> ~/directory2/7120599_S*.txt"

顺便说一下,如果您设置了
POSIXLY\u CORRECT
环境变量,您可以强制Bash遵循POSIX。

您使用的是什么shell
echo$SHELL
你确定
~/directory2/7120599_S7.txt
已经存在吗?@Schwern当我键入
echo$SHELL
时,我得到了
/bin/bash
。我想我用的是BASH shell<代码>~/directory2/7120599_S7.txt存在