I came across this older article from 2020 and I found it informative. It’s about how the shell does globbing and the potential issues it can cause if not understood correctly.

TLDR:

find . -not -name *.py -delete and find . -not -name '*.py' -delete will behave differently in certain scenarios.

In the first example, the shell will replace the wildcard pattern with a list of matching file names IF there are any matches in the current directory. If there isn’t, then it won’t do anything and will pass *.py to find.

In the second example, the shell won’t do any globbing at all and will just pass *.py

  • Consti@lemmy.world
    link
    fedilink
    arrow-up
    3
    ·
    22 hours ago

    Using zsh will gelp with that mistake, because by default it will turn the ‘no matches’ scenario into an error. But seriously, always quote your arguments if there is any chance for ambiguity (also for variables)