Linux 使用Perl脚本提取tar.gz文件
我正在编写一个关于使用指定位置提取tar.gz文件的Perl脚本,但是当我运行我的代码时Linux 使用Perl脚本提取tar.gz文件,linux,perl,unix,Linux,Perl,Unix,我正在编写一个关于使用指定位置提取tar.gz文件的Perl脚本,但是当我运行我的代码时 use strict; use warnings; use Archive::Tar; use File::Spec::Functions qw(catdir); my $input = "sample.tar.gz"; my $tar = Archive::Tar->new($input); my @files = $tar->list_files;
use strict;
use warnings;
use Archive::Tar;
use File::Spec::Functions qw(catdir);
my $input = "sample.tar.gz";
my $tar = Archive::Tar->new($input);
my @files = $tar->list_files;
my $output_dir = '/var';
foreach my $file (@files) {
my $extracted_file = catdir($output_dir, $file);
$tar->extract_file($file, $extracted_file);
if ($file =~ /\.rpm\z/ /\.sh\z/ /\.gz\z/) {
open my $fh, '<', $extracted_file or do { warn "$0: Can't open file $file: $!"; next };
while (defined(my $line = <$fh>)) {
do something with $line
}
close $fh;
}
}
有人能帮我解决这个问题吗?你有两个选择;第一)脚本的第一行应该是(首先搜索路径)#/usr/bin/env perl
或直接指向perl安装路径(我的位于#!/usr/bin/perl
)
最后,通过使用perl
perl extract.pl
缺少一个shebang,告诉您的脚本应该使用哪个解释器 请加上: #/bin/perl
在第一行。请在第一行使用
#!/usr/bin/perl
或安装perl的任何路径
或者执行脚本作为
perl extract.pl
您的脚本正在您的默认shell
中进行解释,我相信这就是bash
因此它无法识别使用,因为bash或任何shell中都没有这样的关键字/命令。
因此出现了错误
use command not found
感谢您的编辑……)我尝试添加shebang,但仍然存在错误。剩下的错误是./extract.pl:第5行:`use File::Spec::Functions qw(catdir);'@user3534255尝试在()之前和之后放置空格。您确定错误消息与第5行的内容相同吗?
use command not found