bash,shell,意外的令牌完成

时间:2016-12-05 22:26:24

标签: bash shell unix

这是我的代码:

echo -n "Enter 3 parameters in format file-num1-num2: "
str=""
while read param
do
        echo $param >|temp
        fname=$(cut -d"-" -f1 temp)
        num1=$(cut -d"-" -f2 temp)
        num2=$(cut -d"-" -f3 temp)
        range=$num1"-"$num2
        head -$num3 $fname >|temp
        tail -$num1 temp >|temp
        st=$fname"-"$(wc -c <temp)
        str=$str" "$st"-"$range
        echo $(wc -c <temp) >>temp2
        echo -n "Enter 3 parameters in format file-num1-num2: "
done
sort temp2 >|temp
c=$(wc -l temp)
c2=0
while [ $c2 -lt $c ]
do
((c2++))
head -$c2 temp >|temp3
tail -1 temp3 >|temp3
num=$(cat temp3)
for x in $str
do
echo $x >| temp4
fname=$(cut -d"-" -f1 temp4)
ran=$(cut -d"-" -f2 temp4)

sh=$(cut -d"-" -f3 temp4)
if [ $ran -eq $num ]
then
echo "The size of file $fname in lines $sh is: $num"
done
done
rm temp
rm temp2
rm temp3
rm temp4

好的问题是当我运行脚本时出现此错误:

./P4.4: line 36: syntax error near unexpected token `done'
./P4.4: line 36: `done'

当我因某种原因运行它时,第一个循环卡住了,我需要按ctrl ^ d来保持它继续下去并做两次离开循环

这就是代码应该做的事情:

输入:

g-5-7
f-2-4

输出:

The size of file f in lines 2-4 is: 16
The size of file g in lines 5-7 is: 10

文件g:

12
34
56
78
910
ab
wz

文件f:

aa
bb c
dd ef
gh x
ttt

1 个答案:

答案 0 :(得分:1)

if [ $ran -eq $num ]
then
echo "The size of file $fname in lines $sh is: $num"
done

if遗漏了fi