版权声明:Summer https://blog.csdn.net/csdnyanglei/article/details/82219540
#/bin/bash
#file name: Max_weather.sh
#funciton: 天气小贴士,显示时间及天气信息,后期可加入雨雪天气邮件发送等功能
#version: 1.0
#地区id集合,这个后期可以从文件外读取
declare -A area_ids
area_ids["nanjing"]=101190101
echo '---------------天气小贴士--------------------'
echo "hello,user!"
echo "today is: "`date`
weather_json=`curl -s http://www.weather.com.cn/data/sk/${area_ids["nanjing"]}.html`
city=`echo $weather_json | jq ".weatherinfo.city"`
temp=`echo $weather_json | jq ".weatherinfo.temp"`
wd=`echo $weather_json | jq ".weatherinfo.WD"`
ws=`echo $weather_json | jq ".weatherinfo.WS"`
echo "your city: "$city" ,temp: "$temp" ℃ ,wind:",$wd$ws
result:
---------------天气小贴士--------------------
hello,user!
today is: 2018年 08月 30日 星期四 12:36:19 CST
your city: "南京" ,temp: "21.9" ℃ ,wind:,"东风""小于3级"