bug-tar
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-tar] How one can do untar a file and gzip its files with one co


From: Stephane Chazelas
Subject: Re: [Bug-tar] How one can do untar a file and gzip its files with one command line?
Date: Wed, 13 Apr 2016 17:26:21 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

2016-04-06 07:46:21 +0300, Sergey Poznyakoff:
> Hi Ehsan,
> 
> A minor point, to begin with:
> 
> > tarfile=file.tar.gz
> [...]
> > tar cvf "$tarfile" "$file1" "$file2"
> 
> Since your file ends in .gz, you probably meant this:
> 
>   tar cvfz "$tarfile" "$file1" "$file2"
>   
> > I want to untar the original file (i.e. file.tzr.gz) and directly gzip
> > the untar files (i.e. file1.fastq and file2.fastq) with one command
> 
> Ok, here it is:
> 
>   tar -vxf file.tar.gz --to-command 'gzip -c > $TAR_FILENAME.gz'
[...]

It would seem "tar" doesn't  invoke a shell to process that
command-line though it seems to do some shell-like parsing: It
understands single quote, double quote and backslash quotings
and expands variables (including withing double quotes), but
doesn't seem to do any other sort of expansions.

In particular, it does word splitting upon variable expansion,
so the examples in the manual are wrong, it should be

tar -x -f archive.tar --to-command='proc "$TAR_FILENAME" "$TAR_SIZE"'

It doesn't perform redirections, so here, we'd need:

CODE='
  gzip -c > "$TAR_FILENAME.gz"
  ' tar -xvf file.tar.gz --to-command 'sh -c "$CODE"'


Or if there are subdirectories:


CODE='
  mkdir -p -- $TAR_FILENAME:h &&
    gzip -c > $TAR_FILENAME.gz
  ' tar -xvf file.tar.gz --to-command 'zsh -c "$CODE"'

In any case, note that it doesn't restore times, ownership,
permissions...

Another option could be to use avfs.

-- 
Stephane



reply via email to

[Prev in Thread] Current Thread [Next in Thread]