in reply to untarring number of files

Why are you using Perl?
#!/bin/sh for file $(ls -1 *.tar) do tar xvf $file done
Or, from the command line ...
ls -1 *.tar | xargs tar xvf

------
We are the carpenters and bricklayers of the Information Age.

The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

... strings and arrays will suffice. As they are easily available as native data types in any sane language, ... - blokhead, speaking on evolutionary algorithms

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Replies are listed 'Best First'.
Re: Re: untarring number of files
by sauoq (Abbot) on Oct 22, 2003 at 19:03 UTC
    Why are you using Perl?

    Maybe he was just sticking with what he knows... and trying to write portable code.

    for file $(ls -1 *.tar)

    First, the error: you need for file in. Secondly, that has portability issues. $( ) works with some Bourne-like shells, such as bash and ksh, but it isn't ubiquitous. You could probably get away with for file in `ls -1 *.tar` but there is really no reason that I know of not to just use a glob like for file in *.tar instead.

    -sauoq
    "My two cents aren't worth a dime.";
    
      Perhaps I'm missing something as well, but having the for loop iterate over the results of 'ls -l' doesn't seem like it'd work, as it would try to untar things like '-rw-rw-r--' and 'Oct'. Perhaps 'ls' would be more appropriate. Heck, you could even leave the external program out of it.
      for file in *tar; do tar xvf $file; done

      thor

      Update:Yeah, I'm an idiot. "ell-ess dash ell" ne "ell-ess dash one". *shrugs*

         You misread '-1' (dash one) as '-l' (dash ell).

         Using -one only produces the filenames and nothing else, so your point isn't a problem.

         Of course this loop does fail for cases where the filename contains either a space or a " character in their names ..

        Steve
        ---
        steve.org.uk
        That's a "one". ;) Gets us all...