【Linux】一些好玩的shell脚本

时间:2022-04-18 08:55:53

更新中……

在用户登录时输出欢迎语句和天气情况

刚刚开始学习Linux shell脚本,功能很简单,不喜勿喷,用了一个免费的api,可以看这里:链接,需要脚本中加入你要查询天气的城市的id,城市id可以在这里查询:链接,用vim打开~/.bash_profile文件添加如下脚本,并将脚本中的url:

http://www.weather.com.cn/data/sk/101270106.html

中的.html前面那串数字改为你的城市id。

#my first shell script
#edit by lixiang in 2017-7-31
echo '-----------------------------------------------'
echo "|||||hello,user!"
echo "|||||today is" `date`
#echo "the weather is:"
json=`curl -s http://www.weather.com.cn/data/sk/101270106.html`
#echo $json
city=`echo $json | sed 's/.*city":"//g'| sed 's/","cityid.*$//g'`
temp=`echo $json | sed 's/.*temp":"//g'| sed 's/","WD.*$//g'`
wd=`echo $json | sed 's/.*WD":"//g'| sed 's/","WS.*$//g'`
ws=`echo $json | sed 's/.*WS":"//g'| sed 's/","SD.*$//g'`
echo '|||||you are now at '$city','$temp'℃,'$ws$wd'.'
echo '-----------------------------------------------'

保存退出,使用ssh登录一下看看,我是使用xshell登录的,效果如下:
【Linux】一些好玩的shell脚本