0

If I run

grep -i "echo" *

I get the results I want, but if I try the following simple bash script

#search.sh
grep -i "$1" *
echo "####--DONE--####"

and I run it with sh -x search.sh "echo" I get the following error output:

' grep -i echo '*
: No such file or directory
' echo '####--DONE--####
####--DONE--####

How come? I'm on CentOS

13
  • 3
    How does echo ####--DONE--#### end up outputting ####--FINE--####? I think there's something you're not showing here. Commented Jan 22, 2012 at 22:39
  • If you run bash -x ... instead of sh -x ..., does it work? Commented Jan 22, 2012 at 22:41
  • 1
    Did you try adding the line #!/bin/bash at the very top of your script and then running the script as ./search.sh "echo"? Commented Jan 22, 2012 at 22:41
  • 4
    Please make sure to show us the exact script and output. My guess is you're running the script from an empty directory and therefore * gives No such file or directory. Commented Jan 22, 2012 at 22:44
  • 2
    That's odd, I don't see why that would fix the problem. Without the #!, the system will use #!/bin/sh to execute the script. Using /bin/sh vs. /bin/bash might make some difference, but not for anything I see here. If you'll copy-and-paste the exact contents of the script, and the exact output, this question might be useful in the future. Commented Jan 23, 2012 at 1:31

2 Answers 2

1

Add the sha-bang line at the top of your script

#!/bin/bash

and after making it executable, run the script using

./search.sh "echo"
Sign up to request clarification or add additional context in comments.

Comments

0

The "sh -x" should print the files that '*' matches. It looks like it's not matching any files. Are you maybe running it in a directory with no readable files?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.