这是我第一次尝试编写代码,现在我需要一些帮助。
我得到一个语法错误,但不知道它在哪里。请您看一下我的代码,告诉我修复语法需要什么,以及我需要改进这个脚本吗?
#!/bin/bash
echo -e "Please Input Website To Get URLS and IPs"
while read line do wget $line -O $line.txt -o /dev/null ls -l $line.txt
grep "href=" $line.txt | cat -d"/" -f3 |grep $line |sort -u > $line-srv.txt
for hostname in $(cat $line-srv.txt);do host $hostname |grep "has adress"
done发布于 2014-07-16 17:30:15
你错过了第二个“完成”。您只终止了一个while循环。
一致的缩进就会发现这一点。也就是说,如果您缩进了循环中的所有内容,那么更明显的是缺少了什么东西。例如。
echo -e "Please Input Website To Get URLS and IPs"
while read line
do
wget $line -O $line.txt -o /dev/null
ls -l $line.txt
grep "href=" $line.txt | cat -d"/" -f3 |grep $line |sort -u > $line-srv.txt
for hostname in $(cat $line-srv.txt);do
host $hostname |grep "has adress"
done发布于 2014-07-16 17:48:57
您可能会发现这更简单:
#!/bin/bash
while read -p "Please Input Website To Get URLS and IP (CTRL-D to exit): " TARGET || { echo >&2; false; }; do
wget -O - -o "/dev/null" "$TARGET" | grep -Po '(?<=://)[^/]+' | grep "$TARGET"
done | sort -u | xargs -r host | grep 'has address'试着运行它,并对您期望的函数与它的比较给出一个注释。
或另一种形式:
#!/bin/bash
while read -p "Please Input Website To Get URLS and IP (CTRL-D to exit): " TARGET || { echo >&2; false; }; do
wget -O - -o "/dev/null" "$TARGET" | grep -Po '(?<=://)[^/]+' | grep "$TARGET" | sort -u | xargs -r host | grep 'has address'
donehttps://stackoverflow.com/questions/24786995
复制相似问题