Search code examples
perl

Using system to extract tar


I am trying to extract a directory with tar files, but it doesn't seem to work correctly. The command works on the command line but not with system in Perl. I really need this to work in Perl.

$tar_dir = "/root/updates/*.tar.bz2";
system ("for i in $tar_dir ; do tar xvfj $i; done");

It works on command line like this:

for i in *.bz2 ; do tar xvfj $i; done


Solution

  • Or, you could move the loop into the Perl code:

    use warnings;
    use strict;
    
    for (glob '/root/updates/*.tar.bz2') {
        system "tar xvfj $_";
    }