Zsh Mailing List Archive
Messages sorted by:
Re: How much of it is zsh?
- X-seq: zsh-users 14965
- From: "Nadav Har'El" <nyh@xxxxxxxxxxxxxxxxxxx>
- To: zzapper <david@xxxxxxxxxx>
- Subject: Re: How much of it is zsh?
- Date: Wed, 24 Mar 2010 14:03:59 +0200
- Cc: zsh-users@xxxxxxx
- Hebrew-date: 9 Nisan 5770
- In-reply-to: <Xns9D456D0F33B88zzappergmailcom@xxxxxxxxxxxx>
- List-help: <mailto:firstname.lastname@example.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:email@example.com>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <Xns9D456D0F33B88zzappergmailcom@xxxxxxxxxxxx>
On Wed, Mar 24, 2010, zzapper wrote about "How much of it is zsh?":
> This is kind of a generic/dumb question I use zsh on cygwin.
> So cygwin provides egrep now some of things grep can do are superceded by for
> instance zsh's **/*.php recursion but presumably I could still use egrep's -
> R. Am I right in thinking egrep knows nothing about the fact that its shell
> is zsh.?!
> Where are the boundaries between a shell and the tools
Unlike MS-DOS where each command had to globbing (expansion of "*" etc.)
for its command-line arguments, traditionally shells on Unix (and therefore,
also cygwin) do this before calling the command. I.e., if the user types
egrep something *.php
The shell (in our case, zsh) first does globbing. E.g., if you have the
files a.php, b.php and c.php, the command is changed by the shell to
egrep something a.php b.php c.php
and only then egrep is run. egrep doesn't know anything about the reason
it got these 3 filenames, or that they were generated by globbing.
You're right that zsh added the very useful *recursive* globbing syntax
that didn't exist in previous shells. In this case, **/*.php matches
recursively files called *.php. But nothing in the way this works changes
from what I described above - i.e., zsh first expands **/*.php into a list
of file names, and then gives this list of filenames to egrep.
You're right that the two commands
egrep -R something dir
egrep something dir/**/*
basically end up doing the same thing, but I don't see why you should
consider this a problem. By the way, if you're curious, there's actually
a subtle difference between the way these two work. Like I said, the shell's
globbing is always done in advance. So if dir has a million files under it,
this will expand into a command with a million arguments - which on some
system can be a problem (too much memory used, or command too long).
On the other hand, egrep -R finds the files recursively one by one, and
never needs to hold the whole list of files in memory.
I hope this answers your question.
Nadav Har'El | Wednesday, Mar 24 2010, 9 Nisan 5770
Phone +972-523-790466, ICQ 13349191 |I put a dollar in one of those change
http://nadav.harel.org.il |machines. Nothing changed.
Messages sorted by: