pistacchio
pistacchio

Reputation: 58873

grep in bash script not working as expected

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

Upvotes: 0

Views: 1254

Answers (2)

gogators
gogators

Reputation: 815

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?

Upvotes: 0

jaypal singh
jaypal singh

Reputation: 77105

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"

Upvotes: 1

Related Questions