Extract a line from a file using the line number

I have a shell script and want to assign a value to a variable. The value is the line exctrated from a file using the line number. The line number it is not fix, and could change any time.
I have tried sed, awk, head .. See my script

# Get randome line number from the file
#selectedline = `awk 'NR==$randomline {print $0}' $filename`
#awk 'NR==$randomline {print $0}' $filename
selectedline=`sed -n "${randomline}{p;q;}" $filename`
#sed -n "${randomline}{p;q;}" $filename
#selectedline=`head -$randomline $filename |tail -1`
#head -${randomline} $filename |tail -1
echo "Random line = $selectedline"
The problem is that after getting the desired line specified by randomline, the entire file is expanded in the variable selectedline. This the case only ,when assigned to a variable.

Need help

# one way
lin=4
file=/path/somefile
sed -n $lin,"$lin"p $file | read myvariable
# another way
myvariable=`awk -v line=$lin "NR==line" $file`