Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Episode 07: find name pattern can be glob expanded, needs quotes #1031

Open
hoytpr opened this issue Sep 6, 2019 · 1 comment

Comments

@hoytpr
Copy link
Contributor

commented Sep 6, 2019

Sorry to intrude again.
What happened:
While comparing the use of quotes for wildcard expansion with the find command (find . -name *.txt vs. find . -name '*.txt') the output of find . -name *.txt changes depending on whether a .txt file is present in the current working directory. Specifically, if haiku.txt is removed, the command find . -name *.txt (without quotes around *.txt) PROCEEDS and returns:

./data/LittleWomen.txt
./data/one.txt
./data/two.txt

After some research it's possible this is my first known encounter with unwanted "globbing". Please advise. Is this due to the shell not finding the wildcard pattern in the current working directory, but the find -name command continues to shell-glob?

What did you expect to happen?
I expected find . -name *.txt (no quotes around *.txt) to allow immediate shell expansion of the wildcard character resulting in no matching files. This would then give no output, or maybe an error that there are no .txt files present in the current working directory.

Is it reasonable to mention how wildcard expansion in the shell is affected by matches in the current working directory? As this might not even be "globbing" I'm way out of my comfort zone here. But something like:

Without quotes around *.txt, the find . -name *.txt command wildcard expansion immediately encounters a matching filename (from the lesson: haiku.txt) in the current working directory and completes (stops). Without this matching filename the command find will begin at . (the current working directory) and recursively identify all filenames matching the pattern (in a process called "globbing" (if this actually is globbing)).

This is a great lesson and (IMO) already pretty advanced. I'm only bringing this up because it's the first thing that happened to me when trying use these tools and work outside the lesson.

Please feel free to close this issue.

@gdevenyi gdevenyi changed the title Episode 07 wildcard expansion and the CWD Episode 07: find name pattern can be glob expanded, needs quotes Sep 10, 2019

@gdevenyi

This comment has been minimized.

Copy link
Contributor

commented Sep 10, 2019

Hi, thanks for the detailed diagnosis. The issue is indeed that the shell is expanding the "*.txt" glob before it gets passed to find, causing problems.

The calls to find should be wrapped with quotes to prevent glob expansion, this is a BUG :)

As for adding a warning, I think maintainers will have to think about that a bit more, but we should fix the find at least 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.