Grabbing top line of text in a file and setting it to a variable

If I have a txt file with

test.txt

somelineoftext

and I want to set that line of text to variable in a script:

so

#!/bin/bash
var=''

becomes

#!/bin/bash
var='somelineoftext'

Im sure I use grep but I don't know what the command would be????

Is there a way of doing that?

var=`head -n 1 test.txt`

What if it was the second line in the text file is that 2?

2 will print two lines from top of file. that is not what you need right.

use either of these

var=`head -n 2 | tail -n 1 test.txt`
var=`awk 'NR==2' test.txt`
var=`sed -n '2,2p' test.txt`