用法 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 |