Shouldn’t it be better to parse the result of 'file $1' for some of the cases?
Many files start with a magic number which tells what this file is meant to be. Of course, some formats may not have a magic number, and in the case of *.tar.gz (or *.tgz) only the outer layer (gunzip) is detected, meaning that the file still has to be unarchived with tar. 'file -Nikpzb <file>' provides relevant information (well, at least under ubuntu, I do not know much for other OSes, like *BSD). On some systems, there is also an utility called 'unp' which guesses what is the archive format and uses the right tool to deal with it. 2014-08-19 3:01 GMT+02:00 Martín Cigorraga <martincigorr...@gmail.com>: > Hi, > I'm trying to adapt a bash function to extract compressed files depending > on the tool used to compress them: > > function ex > > # ex - archive extractor > > # usage: ex <file> > > if test -f $1 > > switch $1 > > case *.tar.bz2 > > tar xjfv $1 > > case *.tar.gz > > tar xzfv $1 > > case *.bz2 > > bunzip2 $1 > > case *.rar > > unrar x $1 > > case *.gz > > gunzip $1 > > case *.tar > > tar xfv $1 > > case *.tbz2 > > tar xjfv $1 > > case *.tgz > > tar xzfv $1 > > case *.xz > > xz -dv $1 > > case *.zip > > unzip $1 > > case *.Z > > uncompress $1 > > case *.7z > > 7z x $1 > > case '*' > > echo "'$1' cannot be extracted via ex()" > > end > > else > > echo "'$1' is not a valid file" > > end > > end > > Of course this isn't working at this time so my question is: how do I do > to make switch correctly parse the file name? > > Best regards, > -Martin > > > ------------------------------------------------------------------------------ > > _______________________________________________ > Fish-users mailing list > Fish-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/fish-users > > -- .../Sedrikov\...
------------------------------------------------------------------------------
_______________________________________________ Fish-users mailing list Fish-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/fish-users