I'm extremely new to Unix, and this is driving me crazy. I am getting this error:
./lines: line 21: [[: grep -c *.* $3: syntax error: operand expected
(error toke n is ".* $3")
./lines: line 26: [[: grep -c *.* $3: syntax error: operand expected
(error toke n is ".* $3")
When running this script:
#!/bin/bash
#lines <start> <finish> <file> prints lines start-finish of file
if [[ $# != 3 ]]
then echo "Command format: lines <starting line> <end line> <filename>"
exit
fi
tLines='grep -c *.* $3'
start=$1
finish=$2
if [[ $finish -lt $start ]]
then echo "$finish is less than $start. I'll go ahead and reverse those for you."
start=$2
finish=$1
fi
start=$((finish-start+1))
if [[ $tLines -lt $start ]]
then echo "$3 is only $tLines lines - that's less than $start"
exit
fi
if [[ $tLines -lt $finish ]]
then echo "3 is only $tLines line - that's less than $finish"
exit
fi
head -$finish $3 | tail -$start
exit
I have no idea what those errors mean and searching them online have not given me much insight. I appreciate any help!