PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Re: how to use unzip with pipe
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Re: how to use unzip with pipe

Réponse
 
LinkBack Outils de la discussion
Vieux 20/08/2006, 20h15   #1
Ilya Zakharevich
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to use unzip with pipe

[A complimentary Cc of this posting was sent to
Danish
<me.linuxadmin@gmail.com>], who wrote in article <1155537414.080719.126630@m79g2000cwm.googlegroups .com>:
> Hi,
> Can anyone please guide me as to how use pipe with unzip. For eg, Iv
> got a lot of zip files in a directory. So id like to `ls` them to a
> pipe and then unzip it.
>
> $ls *.zip
>
> 1.zip
> 2.zip
>
> Can I do
> $ls *.zip | unzip
>
> I tried it, but was not working...Tried googling but didnt find
> much..Need it urgently


Out of tens of postings, nobody gave a "correct" one:

unzip "*.zip"

Hope this s,
Ilya



  Réponse avec citation
Vieux 21/08/2006, 10h07   #2
Danish
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to use unzip with pipe


Ilya Zakharevich wrote:
> [A complimentary Cc of this posting was sent to
> Danish
> <me.linuxadmin@gmail.com>], who wrote in article <1155537414.080719.126630@m79g2000cwm.googlegroups .com>:
> > Hi,
> > Can anyone please guide me as to how use pipe with unzip. For eg, Iv
> > got a lot of zip files in a directory. So id like to `ls` them to a
> > pipe and then unzip it.
> >
> > $ls *.zip
> >
> > 1.zip
> > 2.zip
> >
> > Can I do
> > $ls *.zip | unzip
> >
> > I tried it, but was not working...Tried googling but didnt find
> > much..Need it urgently

>
> Out of tens of postings, nobody gave a "correct" one:
>
> unzip "*.zip"
>
> Hope this s,
> Ilya


Thank you very much
Danish

  Réponse avec citation
Vieux 21/08/2006, 11h16   #3
Stephane Chazelas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to use unzip with pipe

On 21 Aug 2006 02:07:22 -0700, Danish wrote:
[...]
>> Out of tens of postings, nobody gave a "correct" one:
>>
>> unzip "*.zip"

[...]

Indeed, there's a bug in unzip that makes it behave the msdos
way even on Unix (where *, ?, [, \ are allowed in filenames).

So the only correct one is

unzip "*.zip"

And if you want to use a for loop or find, you need to escape
the *, ?, \ and [ characters first in filenames:

Something like:

for f in ./*.zip; do
[ -f "$f" ] || continue
[ -L "$f" ] && continue
escaped_f=$(
printf '%s\n' "$f" | sed 's/[][\?*]/\\&/g'
)
unzip "$escaped_f"
done

--
Stephane
  Réponse avec citation
Vieux 21/08/2006, 15h03   #4
Chris Mattern
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to use unzip with pipe

Stephane Chazelas wrote:
> On 21 Aug 2006 02:07:22 -0700, Danish wrote:
> [...]
>
>>>Out of tens of postings, nobody gave a "correct" one:
>>>
>>> unzip "*.zip"

>
> [...]
>
> Indeed, there's a bug in unzip that makes it behave the msdos
> way even on Unix (where *, ?, [, \ are allowed in filenames).
>
> So the only correct one is
>
> unzip "*.zip"
>
> And if you want to use a for loop or find, you need to escape
> the *, ?, \ and [ characters first in filenames:
>
> Something like:
>
> for f in ./*.zip; do
> [ -f "$f" ] || continue
> [ -L "$f" ] && continue
> escaped_f=$(
> printf '%s\n' "$f" | sed 's/[][\?*]/\\&/g'
> )
> unzip "$escaped_f"
> done
>


Dear God, that's ugly. Whoever decided unzip shouldn't
handle a list of filenames but *should* try to do its own
globbing needs to be shot.


Chris Mattern
  Réponse avec citation
Vieux 19/09/2006, 09h33   #5
Ilya Zakharevich
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to use unzip with pipe

[A complimentary Cc of this posting was sent to
Chris Mattern
<syscjm@gwu.edu>], who wrote in article <12ejf8nmrj4o0e7@corp.supernews.com>:
> >>>Out of tens of postings, nobody gave a "correct" one:


> >>> unzip "*.zip"


> Dear God, that's ugly. Whoever decided unzip shouldn't
> handle a list of filenames but *should* try to do its own
> globbing needs to be shot.


Opionions differ. IMO, whoever got this (broken) idea that it is the
shell who globs (and not CRTL of the called application) should be
treated unmercifully.

Only the arguments which are meaningful to be globbed should be
globbed, and only the application knows its syntax to support this.
Otherwise you get this "just do not have a file named `-rf'" logic.

Of course, this flaw can't be easily fixed in current Unix shells
(well, interaction with `complete' database can somewhat here).
But whoever (?) wants to design a better shell (on a system with
not-yet finished CRTL ;-), could revisit this problem.

But I already expressed this opinion many times...

Hope this s,
Ilya
  Réponse avec citation
Vieux 19/09/2006, 11h12   #6
Daniel Rock
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to use unzip with pipe

Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
> Opionions differ. IMO, whoever got this (broken) idea that it is the
> shell who globs (and not CRTL of the called application) should be
> treated unmercifully.


Why should the wheel be reinvented for each and every application what
can be done in a consistent manner by a single instance (the shell)?

--
Daniel
  Réponse avec citation
Vieux 21/10/2006, 09h58   #7
Ilya Zakharevich
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to use unzip with pipe

[A complimentary Cc of this posting was sent to
Daniel Rock
<v200638@deadcafe.de>], who wrote in article <eeofqi$26a7$2@server.rock.net>:
> Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
> > Opionions differ. IMO, whoever got this (broken) idea that it is the
> > shell who globs (and not CRTL of the called application) should be
> > treated unmercifully.

>
> Why should the wheel be reinvented for each and every application


Not in applications; as I said, the default, "legacy-compatible",
globbing would be done in CRTL. The applications should be able to
override this.

> what can be done in a consistent manner by a single instance (the
> shell)?


By definition, shell can't do any reasonable globbing; otherwise you
get the "just do not have a file named -rf" syndrom. Only the
application knows which arguments can have a meaning of a
file-pattern, so may be globbed.

Hope this s,
Ilya
  Réponse avec citation
Vieux 21/10/2006, 12h02   #8
Daniel Rock
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to use unzip with pipe

Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
> Only the application knows which arguments can have a meaning of a
> file-pattern, so may be globbed.


.... and that in a wonderful inconsistent way:

C:\> cd Prog*
C:\Programme>

Note: Globbing is technically wrong here since "cd" only expects a single
directory name as an argument.

[In a directory with lots of .TXT-Files]

C> notepad *.txt
[a dialog pops up
The syntax for file name, directory name or volume name is wrong
(manually translated)]

Note: Globbing makes sense here because I might want to edit multiple files
at the same time.

It's better let this shell doing this. And your famous "-rf" filename:
-- is your fried. A much better work-around than begging for each
application programmer implementing globbing consistent.


> Hope this s,


Hope this s,

--
Daniel
  Réponse avec citation
Vieux 21/10/2006, 18h17   #9
Spiros Bousbouras
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to use unzip with pipe

Ilya Zakharevich wrote:

> [A complimentary Cc of this posting was sent to
> Daniel Rock
> <v200638@deadcafe.de>], who wrote in article <eeofqi$26a7$2@server.rock.net>:
> > Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
> > > Opionions differ. IMO, whoever got this (broken) idea that it is the
> > > shell who globs (and not CRTL of the called application) should be
> > > treated unmercifully.

> >
> > Why should the wheel be reinvented for each and every application

>
> Not in applications; as I said, the default, "legacy-compatible",
> globbing would be done in CRTL. The applications should be able to
> override this.


What's CRTL ?

> > what can be done in a consistent manner by a single instance (the
> > shell)?

>
> By definition, shell can't do any reasonable globbing; otherwise you
> get the "just do not have a file named -rf" syndrom. Only the
> application knows which arguments can have a meaning of a
> file-pattern, so may be globbed.


Yet , in the vast majority of cases the globbing the shell does
works fine. The only time globbing produced unexpected results
for me was years ago when I accidentally ended up with a file whose
name started with - in my home directory.

But I can't evaluate the alternative you're proposing because
I don't know what CRTL is.

  Réponse avec citation
Vieux 21/10/2006, 19h05   #10
Kenny McCormack
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to use unzip with pipe

In article <1161451035.629566.108520@m73g2000cwd.googlegroups .com>,
Spiros Bousbouras <spibou@gmail.com> wrote:
>Ilya Zakharevich wrote:
>
>> [A complimentary Cc of this posting was sent to
>> Daniel Rock
>> <v200638@deadcafe.de>], who wrote in article <eeofqi$26a7$2@server.rock.net>:
>> > Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
>> > > Opionions differ. IMO, whoever got this (broken) idea that it is the
>> > > shell who globs (and not CRTL of the called application) should be
>> > > treated unmercifully.
>> >
>> > Why should the wheel be reinvented for each and every application

>>
>> Not in applications; as I said, the default, "legacy-compatible",
>> globbing would be done in CRTL. The applications should be able to
>> override this.

>
>What's CRTL ?


C Run Time Library

The idea is that it could be consistent at the application level (all
applications uses the same startup code and run time libraries would get
the same globbing behavior).

Anyway, my 2 cents worth is that the Unix/shell way is the right way,
but that there should be a way for the application to get at the raw,
unparsed command line if it needs/wants to. Windows (sort of) gives you
this via the COMMANDLINE environment variable.

  Réponse avec citation
Vieux 14/11/2006, 02h12   #11
Ilya Zakharevich
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to use unzip with pipe

[A complimentary Cc of this posting was sent to
Daniel Rock
<v200642@deadcafe.de>], who wrote in article <ehcuod$pe2$1@server.rock.net>:
> Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
> > Only the application knows which arguments can have a meaning of a
> > file-pattern, so may be globbed.

>
> ... and that in a wonderful inconsistent way:
>
> C:\> cd Prog*
> C:\Programme>
>
> Note: Globbing is technically wrong here since "cd" only expects a single
> directory name as an argument.
>
> [In a directory with lots of .TXT-Files]
>
> C> notepad *.txt
> [a dialog pops up
> The syntax for file name, directory name or volume name is wrong
> (manually translated)]
>
> Note: Globbing makes sense here because I might want to edit multiple files
> at the same time.


I have no idea examples of what are your examples. What are you
trying to proof? That implementation of globbing may be goofy?
Implementation of anything can be goofy...

> It's better let this shell doing this.


My point is that it is not.

> And your famous "-rf" filename:
> -- is your fried.


Do not think so. If you think so, try creating an alias which would
insert -- automatically unless I want to put options.

> A much better work-around than begging for each
> application programmer implementing globbing consistent.


Apparently, you did not read what I wrote. There are only two places
to implement globbing: in CRTL startup code - for backward
compatibility, and in getopt().

Hope this s,
Ilya
  Réponse avec citation
Vieux 14/11/2006, 09h14   #12
Daniel Rock
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to use unzip with pipe

Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
> [A complimentary Cc of this posting was sent to
> Daniel Rock <v200642@deadcafe.de>,


Don't! Either post or eMail but but both. BTW my eMail addresses are only
valid for two weeks. So better hurry next time. And please cut down your
entry novel to a single line.

> who wrote in article <ehcuod$pe2$1@server.rock.net>:
>> Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:

> I have no idea examples of what are your examples. What are you
> trying to proof? That implementation of globbing may be goofy?


Yes, and that's why it should be done in one central place: Then the
behaviour is always consistent.

> Do not think so. If you think so, try creating an alias which would
> insert -- automatically unless I want to put options.


So don't create an alias.

> Apparently, you did not read what I wrote. There are only two places
> to implement globbing: in CRTL startup code - for backward
> compatibility, and in getopt().


No, leave it to the shell, where it belongs. If you don't want globbing
use quotes.
You then know that your command line arguments are always subject to globbing
and don't have to test if and how your application does it.


> Hope this s,


No,


Daniel

P.S. Why do you post an answer always a month after the previous one? Do you
want to have the last word - hoping that I have already forgotten this
thread?
  Réponse avec citation
Vieux 14/11/2006, 10h34   #13
Bruce Barnett
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to use unzip with pipe

"Daniel Rock" <v200646@deadcafe.de> writes:

> Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
>> [A complimentary Cc of this posting was sent to
>> Daniel Rock <v200642@deadcafe.de>,

>
> Don't! Either post or eMail but but both. BTW my eMail addresses are only
> valid for two weeks.



Ah. I bet I can get the next address. 42 of 52.
(I use a timestamp in my e-mail as well.)

--
Sending unsolicited commercial e-mail to this account incurs a fee of
$500 per message, and acknowledges the legality of this contract.
  Réponse avec citation
Vieux 20/11/2006, 10h09   #14
Ilya Zakharevich
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to use unzip with pipe

[A complimentary Cc of this posting was NOT [per weedlist] sent to
Daniel Rock
<v200646@deadcafe.de>], who wrote in article <ejc1cv$1ugo$1@deadcafe.de>:
> > I have no idea examples of what are your examples. What are you
> > trying to proof? That implementation of globbing may be goofy?

>
> Yes, and that's why it should be done in one central place: Then the
> behaviour is always consistent.


If you like consistency so much, just make argc to be always 1. This
is also a consistent behaviour.

Consistency is not the ONLY desired target.

> > Do not think so. If you think so, try creating an alias which would
> > insert -- automatically unless I want to put options.

>
> So don't create an alias.


So one is back to "just do not have file named -rf".

> No, leave it to the shell, where it belongs.


Well, the whole idea is that it does not belong there (except for
histerical raisins).

Hope this s,
Ilya
  Réponse avec citation
Vieux 22/11/2006, 13h36   #15
Daniel Rock
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to use unzip with pipe

Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
> [A complimentary Cc of this posting was NOT [per weedlist] sent to
> Daniel Rock
> <v200646@deadcafe.de>], who wrote in article <ejc1cv$1ugo$1@deadcafe.de>:


One line should still be sufficient.


> If you like consistency so much, just make argc to be always 1. This
> is also a consistent behaviour.


What are you trying to say?


> Consistency is not the ONLY desired target.


But inconsistency is undesired most of the time.


> So one is back to "just do not have file named -rf".


No: Simply use your brain. If you don't trust the directories you are in
first take a quick look.


> Well, the whole idea is that it does not belong there (except for
> histerical raisins).


From posts of other people in this thread your opinion is a minory here.


> Hope this s,


No,


Daniel
  Réponse avec citation
Vieux 22/12/2006, 20h54   #16
Ilya Zakharevich
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to use unzip with pipe

[A complimentary Cc of this posting was NOT [per weedlist] sent to
Daniel Rock
<v200647@deadcafe.de>], who wrote in article <ek1jp6$2kmb$1@deadcafe.de>:
> > So one is back to "just do not have file named -rf".

>
> No: Simply use your brain. If you don't trust the directories you are in
> first take a quick look.


Year, right. This is just like saying that `ls *.txt` is as good as
*.txt: just quickly look and check whether there are files funny chars
in the names...

> > Well, the whole idea is that it does not belong there (except for
> > histerical raisins).


> From posts of other people in this thread your opinion is a minory here.


Now I wonder why this won't scare me...

Hope this s,
Ilya
  Réponse avec citation
Vieux 23/12/2006, 17h39   #17
Daniel Rock
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to use unzip with pipe

[Ilya Zakharevich <nospam-abuse@ilyaz.org> again waited weeks before
posting a response]

I'm tired of you. Good bye.

--
Daniel
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h24.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,22115 seconds with 25 queries