help-bash
[Top][All Lists]
Advanced

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

Re: Explain difference between *.sh and “*.sh”


From: Greg Wooledge
Subject: Re: Explain difference between *.sh and “*.sh”
Date: Thu, 17 Jun 2021 16:25:42 -0400

On Thu, Jun 17, 2021 at 03:00:41PM -0500, Tony Esposito wrote:
> Hello,
> Given the command lines below and logged in as ‘root’ on RedHat Linux, why
> do I get different results?
> 
> find / -name *.sh
> 
> and
> 
> find / -name “*.sh”

You're using non-ASCII quotes here, but I'm going to assume this is an
artifact of your mail user agent, and that you actually had regular ASCII
quotes in the shell command.

In the first command, the shell expands *.sh based on the files in the
current working directory, whatever they may be.  Then it passes this
list, along with the preceding argument words, to become the arguments
of the find command.

So for example, the first command may end up running something like

  find / -name foo.sh hello.sh test.sh 

This is clearly not what you want.

The second command uses quotes to suppress the shell's filename expansion,
and simply passes the literal string *.sh as an argument to find.  Then,
the find command will use that as a pattern to perform its own matching.

That's what you want.



reply via email to

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