Issue with passing variable to Grep in a shell script

Hi,

I'm trying to check if methods specified in a class have been added to the corrosponding interface.

My code below is giving me the following errors:

grep: function: No such file or directory
grep: import($zipfile): No such file or directory
grep: function: No such file or directory
grep: export($backup_file: No such file or directory
grep: =: No such file or directory
grep: null): No such file or directory

It looks like grep is trying to use the pattern I'm giving it as the file ? I'm not sure why though

I've made the line where I think the issue is bold

For reference these are the two lines in WorkingClass.txt

	public function import($zipfile) {
	public function export($backup_file = null) {

and these are the two lines in WorkingInterface.txt

    public function import($zipfile);
	public function export($backup_file = null);
#!/bin/bash
#set -x 

# Navigate to the model directory
cd `dirname $0`/../../webapp/_lib/model

#Get the number of lines in the class We need to pipe the output of WC to awk as it prints the name of the file also) 
classLength=$(wc -l WorkingClass.txt | awk '{print $1}')

# Variable to keep track of which line were on
counter=0

# Variable to track if we find the method in the interface
errors=false


#For each method in the class
while [ $classLength -ne $counter ]
do

# Method were looking for
methodToCheck=$(head -1 WorkingClass.txt)
methodToCheck=${methodToCheck/'{'/''}
#echo 'Looking for' $methodToCheck

#Check its in interface
grep -q $methodToCheck WorkingInterface.txt

#echo $?

if [ $? = "0" ]; then
	#remove the top line of working class and increment counter
	sed -i -e "1d" WorkingClass.txt
	#echo 'Found ' $methodToCheck 

else
	#echo $methodToCheck ' not present in ' $interfaceToCheck
	errors=true
	sed -i -e "1d" WorkingClass.txt
fi


#Get the next method
counter=`expr $counter + 1`


done

#echo 'Problems = ' $errors

Any idea how to fix the problem ?

Thanks :slight_smile:

$methodToCheck --> there may be multiline value in this variable

grep -q "$methodToCheck" WorkingInterface.txt
```[/b]


---------- Post updated at 07:18 PM ---------- Previous update was at 07:15 PM ----------

```text
$ a="one two three" 
$ echo $a
one two three

$ echo "one two three four" > mytest

$ grep $a mytest 
grep: two: No such file or directory
grep: three: No such file or directory
mytest:one two three four

$ grep "$a" mytest 
one two three four