专注各种脚本编程
Baidu
加入收藏夹
本站内容有下面分类知识,欢迎您的到来^_^
shell相关:指令篇 基础篇 脚本欣赏 编程实例 shell问问 shell视频教程 技巧篇 水平测试 E文资料 vi编辑器 高级Bash脚本编程指南
其他:mysql perl c语言 oracle
当前位置:| 主页>shell脚本欣赏>

天气预报(限国内城市)

百度收藏 QQ搜藏

用法
WeatherReport 城市名
如城市名为空则默认为南京

刚学SHELL,请高手指教
=============================================================================
#weather reporter@chainone
place=$1
if test "$place" = ""
then
place="南京"
fi

rm -f index.shtml
wget -q http://weather.sina.com.cn/text/index.shtml


ifzhixia=$(grep "$place" -c index.shtml)
if test "$ifzhixia" = 2
then
cat index.shtml | grep "$place" -A 3 |sed '1d' | grep '>.\+<' -o |tr -d '<'|tr -d '>' > .weathertemp2
elif test "$ifzhixia" = 1
then
cat index.shtml | grep "$place" -A 3 | grep '>.\+<' -o |tr -d '<'|tr -d '>' > .weathertemp2
#cat index.shtml | grep "$place" -A 3 | grep '>.\+<' -o |sed 's/.//' | sed 's/.$//' > .weathertemp2
else
echo "没有该城市的天气讯息!"
exit 0
fi

placetitle="城市: "
condition="天气状况: "
wind="风向风力: "
tempr="最低温度: "
echo "$placetitle" > .weathertemp
echo "$condition" >> .weathertemp
echo "$wind" >> .weathertemp
echo "$tempr" >> .weathertemp

paste .weathertemp .weathertemp2
rm -f index.shtml

上一篇:将一个大文件分割成N个小文件 下一篇:通过输入年月日来计算星期

power by soyo123 2007-2008