On Tue, 2025-08-05 at 11:36 +0100, Barry wrote:
> 
> > On 5 Aug 2025, at 08:01, Michael D. Setzer II via users 
> > <[email protected]> wrote:
> > 
> > Interesting. Wasn't sure why the * in an empty directory would have
> > commands work but if in directory with files it would not?
> 
> The bash shell will pass on the wildcard, * is your example, if it cannot 
> expand the wildcard.
> Some other shell will instead print an error, I think zsh is like that.
> 
> Barry

Mostly true, but the full story is more complicated:

From 'info bash':

   After word splitting, unless the ‘-f’ option has been set (*note The Set
   Builtin::), Bash scans each word for the characters ‘*’, ‘?’, and ‘[’.
   If one of these characters appears, and is not quoted, then the word is
   regarded as a PATTERN, and replaced with an alphabetically sorted list
   of filenames matching the pattern (*note Pattern Matching::).  If no
   matching filenames are found, and the shell option ‘nullglob’ is
   disabled, the word is left unchanged.  If the ‘nullglob’ option is set,
   and no matches are found, the word is removed.  If the ‘failglob’ shell
   option is set, and no matches are found, an error message is printed and
   the command is not executed.  If the shell option ‘nocaseglob’ is
   enabled, the match is performed without regard to the case of alphabetic
   characters.
   
You don't need to worry about this unless you've set one of those
options, i.e. if the pattern doesn't match any files, it gets passed
literally. Best practice is to always use an escape (\*, \? etc.) when
you want to pass the pattern on to the command.

poc
-- 
_______________________________________________
users mailing list -- [email protected]
To unsubscribe send an email to [email protected]
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/[email protected]
Do not reply to spam, report it: 
https://pagure.io/fedora-infrastructure/new_issue

Reply via email to