Linux-指令碼-天氣小貼士
阿新 • • 發佈:2018-11-10
#/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級"