problem using gunzip within a script
Morning,
got a small script to uncompress and untar a bunch of files. The command works when I run it against 1 file on the command line, but when I stick it in a script in a for loop, it doesn't work. I've got for file in `ls *.bd.tar.gz` do gzip -dc $file | tar xvf - done It's probably something obvious, but I can't see what it is. Any suggestions would be welcome. |
What does "it doesn't work" mean? Any error message? Unexpected behaviour? Your script works fine for me, but I wonder what prevents you from using
Code:
tar xvf $file |
Quote:
I can also verify that the script works. So my guess is that your filenames might contain spaces. The for-loop will not process them properly in this case. That is why you should avoid parsing 'ls'. Try this instead: Code:
for file in *.bd.tar.gz |
Morning,
yep, sorry about the lack of information re: the errors in the original post. Getting 2 errors for each $file: e.g. with a filename of jobs.bd.tar.gz gzip: jobs.bd.tar.gz.gz: No such file or directory tar: blocksize = 0 The gzip error message looks like it's appending an extra ".gz" to the end of the file name, and the fact the .gz.gz file doesn't exist probably explains the 2nd message. Hope this helps. Regards, DG. |
solved - thanks
Morning,
as suggested by the 2 responses, parsing the output of the ls seems to have been the cause of my issue. Tried the code suggested by crts and it works. Thanks for the help chaps. DG. |
All times are GMT -5. The time now is 01:24 AM. |