until的用法问题
时间:2011-08-05
来源:互联网
刚接触shell这个东西 在学习这个脚本 其中有几个问题 希望高人指点:
第一,那个wget下载是是整个网站吗,那样的话不会很慢吗?
第二,那个用wget下载的链接是如何做的?
第三,在下载了网站之后,对那个搜索所需信息的两条代码不解。
这个脚本我试着运行过,但无论输入任何城市得到的都是“没有该城市的天气讯息”。
纯新手,求勿鄙视,谢谢了啊!!
代码:
#!/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
#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
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28