Problem with Maths

Heres a script i wrote as a bit of practise. What it does is insert a line in the middle of a file. The line being $1 and the file being $2

#!/bin/bash

rm tempfile
touch tempfile

count=1
linenum= `wc -l < $2`
if [ "$linenum" -eq 0 ]
then
echo $1 >> $2
else

even=`expr "$linenum" % 2`
if [ "$even" -eq 0 ]
then
midline=`expr "$linenum" / 2`
else
midline=`expr "$linenum" / 2`
midline=`expr "$midline" + 0.5`
fi

while [ "$linenum" -gt 0 ]
do
sed -n '$count p' $2 >> tempfile

if [ "$linenum" -eq "$midline" ]
then
echo $1 >> tempfile
fi

count=`expr "$count" + 1`
linenum=`expr "$linenum" - 1`
done
fi
cat tempfile > $2

However when I run this I get the following errors:

testscript: 0: command not found
testscript: [: : integer expression expected
expr: non-numeric argument
testscript: [: : integer expression expected
expr: non-numeric argument
expr: non-numeric argument
testscript: [: : integer expression expected

This would suggest that the expr argument does not have numbers in it. I know I have the variables in double quotes but this should not matter should it. Can anyone help me with any of these errors.

Remove the quotes.

For ex:

if [ "$linenum" -eq "$midline" ] must be

if [ $linenum -eq $midline ]

Cheers

I removed the quotes as you said but it doesn't change anything. I still get the same errors as before.

The problem is:
linenum= `wc -l < $2`
No spaces on either side of the equals sign. Get rid of that space between the equals sign anf the first backquote.