I'm trying to write a shell script that outputs the nth line from a file called file.txt, but I keep getting various errors; one of them including
Line 7: [: 10 file.txt: integer expression expected
and so I cant seem to make it work. What am I doing wrong?
# Read from the file file.txt and output the tenth line to stdout.
#!/bin/bash
len=`wc -l file.txt`
echo $len
if [ "$len" -lt 10 ]
then
errormessage="File too short"
echo $errormessage
exit 0
fi
var=`sed '10q;d' file.txt`
echo $var