学习Linux 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 '>.\+' > .weathertemp2
elif (($ifzhixia==1))
then
cat index | grep "$place" -A 3 | sed '1d' |grep '>.\+' > .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
就这么简单!