Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1129549
  • 博文数量: 153
  • 博客积分: 10576
  • 博客等级: 上将
  • 技术积分: 2137
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-02 21:01
文章分类

全部博文(153)

文章存档

2009年(43)

2008年(110)

分类: LINUX

2008-07-21 15:48:37

学习shell来,第一个完整的脚本程序,参考了网友的代码,修改了一些重要的错误,继续加油


#!/bin/bash
#weather.sh
#使用方法 weather.sh 城市,默认城市为石家庄

if [ -n "$1" ]
then
place="$1"
else
place="石家庄"
fi


rm -f index.shtml
wget -q

 iconv -f gb18030 -t utf8 -o index index.shtml


ifzhixia=$(grep "$place" -c index)


if (($ifzhixia==2))

then
cat index | grep "$place" -A 3 |sed '1,2d' | grep '>.\+<' -o |tr -d '<'|tr -d '>' > .weathertemp2
elif (($ifzhixia==1))

then
cat index | grep "$place" -A 3 | sed '1d' |grep '>.\+<' -o |tr -d '<'|tr -d '>' > .weathertemp2

else
echo "没有该城市的天气讯息!"
exit 0
fi

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

echo -e "$place今天的天气情况为:\n"

paste .weathertemp .weathertemp2
rm -f index.shtml .weathertemp .weathertemp2 index
exit 0

阅读(1689) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~