我对 Unix 非常陌生,这让我发疯。我收到此错误:
./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")
运行此脚本时:
#!/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
我不知道这些错误是什么意思,在网上搜索它们并没有给我太多的洞察力。我很感激任何帮助!