help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why echo without quotes need to glob the file


From: wang yuhang
Subject: Re: Why echo without quotes need to glob the file
Date: Wed, 14 Dec 2022 10:51:09 +0800

on Tue, 13 Dec 2022 09:15:53 -0500 Greg Wooledge via wrote:
> [--hello] is an example of a "glob", which is a pattern that can match
> one or more filenames.  Other examples of globs are *.txt or foobar.[ch]
> Since your glob is not quoted, the shell expands it to a list of filenames
> that it matches in the current directory.
> If you want [--hello] NOT to be expanded, put quotes around it.  Either
> single quotes or double quotes will do.

I konw the right thing to do is put quotes around it, I just don't 
understand that bash regards [-- hello] as a glob to match filenames in `echo`

on Tue, 13 Dec 2022 08:28:25 -0600 G. Branden Robinson via wrote:
> As Greg pointed out, "echo" isn't doing any pattern-matching here, the
> shell is.  If you run an external command called "echo", e.g.,
> "/bin/echo" and inspect its argument list with strace(1), you can see
> this.  (On my system, it shows up as the first line, in "execve()".

> That would be a good question for the TUHS mailing list; perhaps John
> Mashey or Steve Bourne, or someone who worked with them at the Bell Labs
> CSRG in the 1970s, could advise on their motivations.

Now I understand that this is just bash's behavior, not echo. this behavior may 
have existed long ago. I should not tangle with it, just follow its correct use.

Thank you very much for your help, both Greg and Branden

reply via email to

[Prev in Thread] Current Thread [Next in Thread]