Variable assignment question

Hello,

I would like to assign number of lines in a file to a variable (to be passed later as an argument to a function). I am doing it like this:

numLines=wc -l < file.txt

which gives an error. Could somebody help?

numLines=$(wc -l < file.txt)

Or if using sh, do

numLines=`wc -l < file.txt`

Thanks!!! It works!