in reply to Re: untarring number of files
in thread untarring number of files

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.";

Replies are listed 'Best First'.
Re: Re: Re: untarring number of files
by thor (Priest) on Oct 23, 2003 at 00:52 UTC
    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*
      That's a "one". ;) Gets us all...

       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