No. of lines in a file (For scripting)

I'm trying to get the number of lines in a file. I know their are a number of ways of doing this like wc -l or nl which lists the file with the line number. The problem is that I want to use the number of lines a certain program has as a variable in my script. So i can't use wc -l as it returns the number of lines and the name of the file. I tryed to use sed to edit this but all I could come up with was something like this:

linenum=`wc -l $2 | sed -e 's/ /::/5;s/::.*//'`

What is does is places a :: after the fifth space (which is just after the number lines) and deletes after this. So before i ran this i got this:
135 myfile
But after i get this:
135

Which would be fine except that when a file has say 35 lines the no. of spaces change. I'm sure their is a pretty simple way of doing this, does anyone have any ideas.

why dont u try it as,

wc -l < filename

Cheers mate