+ -
当前位置:首页 → 问答吧 → until的用法问题

until的用法问题

时间:2011-08-05

来源:互联网

刚接触shell这个东西 在学习这个脚本 其中有几个问题 希望高人指点:

代码:
#!/bin/bash
#weather.sh
#使用方法 weather.sh 城市,默认城市为上海
if [ -n "$1" ]  #判断输入是否为空
then
place="$1"
else
place="北京"
fi
rm -f index.shtml
wget -q http://weather.sina.com.cn/text/index.shtml
iconv -f GB2312 -t UTF-8 index.shtml > index.shtml1
ifzhixia=$(grep "$place" -c index.shtml1)
if [ "$ifzhixia" = 2 ]
then
cat index.shtml | grep "$place" -A 3 |sed '1d' | grep '>.\+<' -o |tr -d '<'|tr -d '>' > .weathertemp2
elif [ "$ifzhixia" = 1 ]
then
cat index.shtml | grep "$place" -A 3 | grep '>.\+<' -o |tr -d '<'|tr -d '>' > .weathertemp2
else
echo "没有该城市的天气讯息!"
#rm -f index.shtml .weathertemp .weathertemp2 index.shtml1
exit 0
fi
condition="天气状况: "
wind="风向风力: "
tempr="最高温度: "
placetitle="城市:"
echo "$placetitle">.weathertemp
echo "$condition" >> .weathertemp
echo "$wind" >> .weathertemp
echo "$tempr" >> .weathertemp
echo -e "$place今天的天气情况为:\n"
paste .weathertemp .weathertemp2
rm -f index.shtml .weathertemp .weathertemp2 index.shtml1
exit 0


第一,那个wget下载是是整个网站吗,那样的话不会很慢吗?
第二,那个用wget下载的链接是如何做的?
第三,在下载了网站之后,对那个搜索所需信息的两条代码不解。
这个脚本我试着运行过,但无论输入任何城市得到的都是“没有该城市的天气讯息”。
纯新手,求勿鄙视,谢谢了啊!!

作者: Archy@jxnu   发布时间: 2011-08-05

只能全部下载后分析。

论坛天气的多了。多参考。

作者: eexpress   发布时间: 2011-08-05

我记得Google有XML的天气信息来着,使用比较方便。

作者: cuihao   发布时间: 2011-08-05

eexpress 写道:
只能全部下载后分析。

论坛天气的多了。多参考。




内个 能推荐个好懂点的不 给个链接???

作者: Archy@jxnu   发布时间: 2011-08-05