Live data from Hacker News

A common mistake involving wildcards and the find command

blog.robertelder.org

11–20 of 148 posts

Re: A common mistake involving wildcards and the find command

#11

Phew! I'm glad I've been hitting the "Happy Case" scenario all these years! Very useful article. And very informative. Summary: Instead of - find . -name *.jpg Use quotes around pattern i.e. find . -name '*.jpg' Edit: Oops, the double-quotes should have been single quotes! Thanks, @lucd. Happy case, like I said!

Wildcards are still expanded inside double quotes.. Yiu have to use single quotes.

Re: A common mistake involving wildcards and the find command

#12
post #5

I wonder if this is also a problem with fish. The globing there is different.

Fish won't pass along the unmatched glob, so in the given example you'd notice that with

    find . -name *.py
it will error initially, because there is no "*.py" in the current directory.

Globbing is still a thing fish as the shell does, and you still need to protect asterisks that need to reach commands, but you're more likely to notice.

(for bash there is also the "failglob" option that I personally recommend)

Disclaimer: I am a fish developer.

Re: A common mistake involving wildcards and the find command

#13
post #11

Phew! I'm glad I've been hitting the "Happy Case" scenario all these years! Very useful article. And very informative. Summary: Instead of - find . -name *.jpg Use quotes around pattern i.e. find . -name '*.jpg' Edit: Oops, the double-quotes should have been single quotes! Thanks, @lucd. Happy case, like I said!

Wildcards are still expanded inside double quotes.. Yiu have to use single quotes.

...or a backslash.

Re: A common mistake involving wildcards and the find command

#15
post #11

Phew! I'm glad I've been hitting the "Happy Case" scenario all these years! Very useful article. And very informative. Summary: Instead of - find . -name *.jpg Use quotes around pattern i.e. find . -name '*.jpg' Edit: Oops, the double-quotes should have been single quotes! Thanks, @lucd. Happy case, like I said!

Wildcards are still expanded inside double quotes.. Yiu have to use single quotes.

That's not true. Variable expansion happens in double quotes, but globs stay untouched.

Re: A common mistake involving wildcards and the find command

#16
As another user mentioned, many POSIX and/or GNU utilities havent aged well. I respect trying to stay portable, but peoples needs change over time and these tools simply havent kept up. Like the other user, I use Fd now instead:

https://github.com/sharkdp/fd

As well as Silver Searcher:

https://github.com/ggreer/the_silver_searcher

while Grep performance is pretty good, its also gotten pretty stale with regard to its defaults and options.

Re: A common mistake involving wildcards and the find command

#17
Putting ‘shellcheck’ in your CI pipeline is a must for me now, after one too many mistakes.

I just finished cleaning away all existing ‘error’ and ‘warning’ level issues in our codebase so that the ‘shellcheck’ CI step can be really strict on code quality.

Re: A common mistake involving wildcards and the find command

#18
post #16

As another user mentioned, many POSIX and/or GNU utilities havent aged well. I respect trying to stay portable, but peoples needs change over time and these tools simply havent kept up. Like the other user, I use Fd now instead: https://github.com/sharkdp/fd As well as Silver Searcher: https://github.com/ggreer/the_silver_searcher while Grep performance is pretty good, its also gotten pretty stale with regard to its…

Wouldn't you have the same problem with fd if you invoke it on unquoted globs? The problem is the semantics of the shell, not find.

Re: A common mistake involving wildcards and the find command

#19
post #11

Earlier quoted context omitted.

Wildcards are still expanded inside double quotes.. Yiu have to use single quotes.

...or a backslash.

I use the backslash. I also specify -type f explicitly when I’m looking for files.

find . -type f -name \*.txt

Now the next article will talk about problems when there’s a space in the file names and you just piped the output into xargs :)

Re: A common mistake involving wildcards and the find command

#20
post #11

Phew! I'm glad I've been hitting the "Happy Case" scenario all these years! Very useful article. And very informative. Summary: Instead of - find . -name *.jpg Use quotes around pattern i.e. find . -name '*.jpg' Edit: Oops, the double-quotes should have been single quotes! Thanks, @lucd. Happy case, like I said!

Wildcards are still expanded inside double quotes.. Yiu have to use single quotes.

Yes but double quotes will work fine in this case -- globs won't be expanded...
Post reply on HN