You seem to be fast and loose with the "$" character.
Are you trying to source a file here? The variable filename1 is undefined as well.
. $filename1
This will read a line of input from stdin and place it in the variable line1
The read command should rarely be used in bash programs. It's better to pipe the output of one command into the input of another using the proper utilities to do the job.
Are you trying to source a file named "./filename2"? Did you mean:
. $filename2
However filename2 would be undefined. Also the exec command will replace this shell with the program indicated by $filename2
Code:
do
if [ $line -eq $line1 ]
echo $line >> filename3
end if
If you wanted to output differing entries in two files, you could use the diff or comm commands instead.
The comm command works on sorted lists and prints out 3 columns. The first is items uniq to list1. The second is items uniq to list2, and the third is items common to both. You can suppress the output of the columns you don't want.
You may also be confusing the "exec" command with the eval command if you are trying to execute a line of code contained in a variable.