Linux 意外标记“fi'”附近出现语法错误;自定义脚本

Linux 意外标记“fi'”附近出现语法错误;自定义脚本,linux,bash,Linux,Bash,不久前,我编写了一个分为两部分的脚本,称为“bips.sh”和“chekdup.sh”,当我测试它时,它显示: bips.sh: line 17: syntax error near unexpected token `fi' bips.sh: line 17: `fi' 以下是脚本: ---bips.sh--- #!/bin/bash -x # find broadcast ip's that reply with 30+ dupes. # i decided to make this s

不久前,我编写了一个分为两部分的脚本,称为“bips.sh”和“chekdup.sh”,当我测试它时,它显示:

bips.sh: line 17: syntax error near unexpected token `fi'
bips.sh: line 17: `fi'
以下是脚本:

---bips.sh---
#!/bin/bash -x
# find broadcast ip's that reply with 30+ dupes.

# i decided to make this script into two sections. when running this make
# sure both parts are in the same directory.
if [ $# != 1 ]; then
echo "$0 <domain - ie: college.edu>"
else
host -l $1 | grep 'has address' | cut -d' ' -f4 > $1.ips
cat $1.ips | cut -d'.' -f1-3 | sort |\
awk '{ print echo ""$1".255" }' > $1.tmp
cat $1.tmp | uniq | awk '{ print "./chekdup.sh "$1"" }' > $1.ping
rm -f $1.ips $1.tmp
chmod 700 $1.ping
./$1.ping
rm $1.ping
fi

注意:我更新了代码,它总是出现错误

读代码太痛苦了,我不得不重写它

#!/bin/bash -x
# find broadcast ip's that reply with 30+ dupes.

if (( $# != 1 )); then
    echo "$0 <domain>"
    echo "example: $0 college.edu"
    exit
fi

host -l $1 |
awk '
    /has address/ {sub(/[0-9]+$/, "255", $NF); ips[$NF]}
    END {for (ip in ips) print ip}
' |
sort |
while read ip; do
    dupes=$( ping -c 2 $ip | grep -oP 'dupl.*\+\K\S+' )
    if [[ $dupes && $dupes -gt 30 ]]; then
        echo "$ip had $dupes dupes"
    fi
done >> bips.results
#/bin/bash-x
#找到广播ip的回复,重复30次以上。
如果($#!=1));然后
回显“$0”
echo“示例:$0 college.edu”
出口
fi
主持人-l$1|
awk'
/具有地址/{sub(/[0-9]+$/,“255”,$NF);ips[$NF]}
结束{for(ip中的ip)打印ip}
' |
分类|
读ip时;做
重复=$(ping-c2$ip | grep-oP'dupl.*\+\K\S+)
如果[[$dupes&&$dupes-gt 30]];然后
echo“$ip有$dupes dupes”
fi
完成>>bips.results

Script
bips.sh
不包含17行。我想它的结尾包含了更多的东西。它充满了不必要的
cat文件| sometool…
snakes。不需要!使用
sometool文件
sometool我添加了注释以使其成为原始脚本。您确定行结尾正确吗?我忘了更改第一行。我把它改成了original@fedorqui:IMHO
如果grep-q dup1$1.out;然后…
更好。我尝试了代码,但现在显示:bips.sh:第21行:意外标记附近的语法错误
done'bips.sh:第21行:
done>>bips.results'
#!/bin/bash -x
# find broadcast ip's that reply with 30+ dupes.

if (( $# != 1 )); then
    echo "$0 <domain>"
    echo "example: $0 college.edu"
    exit
fi

host -l $1 |
awk '
    /has address/ {sub(/[0-9]+$/, "255", $NF); ips[$NF]}
    END {for (ip in ips) print ip}
' |
sort |
while read ip; do
    dupes=$( ping -c 2 $ip | grep -oP 'dupl.*\+\K\S+' )
    if [[ $dupes && $dupes -gt 30 ]]; then
        echo "$ip had $dupes dupes"
    fi
done >> bips.results