Operating System - HP-UX
1828584 Members
2429 Online
109982 Solutions
New Discussion

Re: Shell Script using find and *

 
SOLVED
Go to solution
Bettina Ofner
Advisor

Shell Script using find and *

My problem is the following:
I want to create a shell script which looks for all files starting with about 8 know characters, input given as variable.
When I try:
find /directory -name ""$name"*" -print
I recieve the following error:
find: cannot stat ....
Which substitution is neccessary to recieve a correct output.
3 REPLIES 3
Andreas Voss
Honored Contributor

Re: Shell Script using find and *

Hi,

your syntax -name ""$name"*" is ok.
The problem is the /directory.
I only get a cannot stat ... when /directory doesn't exists.

Regards
John Palmer
Honored Contributor
Solution

Re: Shell Script using find and *

Hi,

You can either choose to quote the name string or to escape the *:-

find /directory -name "$name*"
or
find /directory -name $name\*

Regards,
John
Alan Riggs
Honored Contributor

Re: Shell Script using find and *

Wildcard substitutions can do strange things when the find command is parsed before execution. Personally, I favor John's second solution (escaping teh wildcard with \)