zsh-users
 help / color / mirror / code / Atom feed
From: "Damien Thébault" <damien.thebault@gmail.com>
To: Heorhi Valakhanovich <valahanovich@tut.by>
Cc: zsh-users@zsh.org
Subject: Re: Why is this happening in zsh?
Date: Thu, 15 Mar 2012 00:19:58 +0100	[thread overview]
Message-ID: <CAEcrOvC2h0JdxoTa_am92yugz2468g8+uo1HV8WOnGkc-zDkqA@mail.gmail.com> (raw)
In-Reply-To: <20120314222918.3a0330b7@tormoz-pc>

On Wed, Mar 14, 2012 at 20:29, Heorhi Valakhanovich <valahanovich@tut.by> wrote:
> This happens in many command processors. I usually use quotes like
>
> fossil --ignore "*.class"
>
> This is not a solution but usual workaround.

Actually, I would say that it is a solution, and not a workaround.

Here is an example with the find command to explain my point of view.

Let's say you want to find files in this tree:

./file1.class
./folder1/file2.class
./folder1/file2.txt
./folder2/file3.class
./folder2/file3.txt

Let see in bash:

 $ find -name *.class
./file1.class
 $ find -name *.txt
./folder2/file3.txt
./folder1/file2.txt

In zsh:
% find -name *.class
./file1.class
% find -name *.txt
zsh: no matches found: *.txt

We can see that in bash, the first command and the second command are
not doing the same thing:
"find -name *.class" is expanded to [find] [-name] [file1.class]
"find -name *.txt" is not expanted and gives [find] [-name] [*.txt]

In zsh, both lines are processed the same way:
"find -name *.class" is expanded to [find] [-name] [file1.class]
"find -name *.txt" does not match anything and returns an error.

Obviously, only the second command in bash is giving the expected
result (find all files with a given extension), in zsh you don't get
any result and the first command is not giving the expected result in
both shells.

To avoid erroneous results like the first command, the wildcard must
be escaped so that it is always sent without modification to the find
command, like this:
 $ find -name "*.class"
./file1.class
./folder2/file3.class
./folder1/file2.class

or
 $ find -name \*.class
./file1.class
./folder2/file3.class
./folder1/file2.class

Escaping the pattern ensures that the command will receive the
expected pattern, you get the following in both bash and zsh:
"find -name \*.class" is expanded to [find] [-name] [*.class]

Not escaping the pattern is a bad habit that will give unexpected
results once in a while (like the example above), so I would say that
zsh's default behavior is good because it makes people understand how
it works and avoid those mistakes.

As it was said before, it's possible to activate the broken bash
behavior in zsh, but I don't think that it's a good solution.

Regards,
-- 
Damien Thebault


  reply	other threads:[~2012-03-14 23:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-14 18:59 Anonymous
2012-03-14 19:29 ` Heorhi Valakhanovich
2012-03-14 23:19   ` Damien Thébault [this message]
2012-03-14 19:42 ` Stephane Chazelas
2012-03-14 19:49 ` Peter Stephenson
2012-03-15 10:13   ` Nomen Nescio
2012-03-15 18:00     ` Kyle Partridge
2012-03-16  0:11       ` Christoph (Stucki) von Stuckrad
2012-03-16  3:28       ` Benjamin R. Haskell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAEcrOvC2h0JdxoTa_am92yugz2468g8+uo1HV8WOnGkc-zDkqA@mail.gmail.com \
    --to=damien.thebault@gmail.com \
    --cc=valahanovich@tut.by \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).