JIZZ Jid
JIZZ Jid

Reputation: 127

How Can i Execute grep in a Script?

When i do the following i get results:

bash$ cat launched | egrep MyTest
MyTest

but with the following script:

#!/bin/sh
result= `cat launched | grep MyTest`
echo $result

when launching the script i get:

bash$ ./test.sh
./test.sh: MyTest: not found

I have full access rights on the script and the script is launched in the same directory as the file launched. How can i fix the script so it will return the same result as above?

Upvotes: 1

Views: 17494

Answers (3)

KevinDTimm
KevinDTimm

Reputation: 14376

Remove the space before the grave accent and your problems go away

Upvotes: 0

Marc B
Marc B

Reputation: 360922

You've got an extra space:

result= `cat launched | grep MyTest`
       ^--- 

variable assignments must not have spaces on either side of the =.

Upvotes: 1

Fred Foo
Fred Foo

Reputation: 363858

Drop the space:

result=`cat launched | grep MyTest`

Even better, drop the UUOC:

result=`grep MyTest launched`

Upvotes: 5

Related Questions