Shell脚本 curl获取必应每日壁纸(Mac OS)
2016-05-10 12:09
766 查看
Mac上Safari不能下载壁纸,遇到好看的很想用作壁纸。写了一小段脚本用来拉取网页图片。
curl:
-sS 参数用来取消下载状态显示
grep 首先把含有图片网址的行提取了出来,针对这一行再做sed替换。
sed刚开始用不是很熟悉。
网上查阅了一下替换的正则形式为 sed 's/一行文本的正则表达/要替换目标文本/'
得到图片URL后,再发起一个curl指令并保存到用户目录下的图片文件夹。
bingPath=`curl -sS http://cn.bing.com|grep "s.cn.bing.net"| sed 's/.*\(http:\\\\\/\\\\\/s.cn.bing.net.*jpg\).*bgDiv.*/\1/'`
# echo $bingPath
picPath=$bingPath
# echo $picPath
picPath=`echo $picPath|sed 's/\\\\//g'`
echo $picPath
picName=`echo $picPath|sed 's/.*http.*\/\(.*\)/\1/g'`
echo $picName
curl $picPath -o $HOME/Pictures/Background/$picName
curl:
-sS 参数用来取消下载状态显示
grep 首先把含有图片网址的行提取了出来,针对这一行再做sed替换。
sed刚开始用不是很熟悉。
网上查阅了一下替换的正则形式为 sed 's/一行文本的正则表达/要替换目标文本/'
得到图片URL后,再发起一个curl指令并保存到用户目录下的图片文件夹。
bingPath=`curl -sS http://cn.bing.com|grep "s.cn.bing.net"| sed 's/.*\(http:\\\\\/\\\\\/s.cn.bing.net.*jpg\).*bgDiv.*/\1/'`
# echo $bingPath
picPath=$bingPath
# echo $picPath
picPath=`echo $picPath|sed 's/\\\\//g'`
echo $picPath
picName=`echo $picPath|sed 's/.*http.*\/\(.*\)/\1/g'`
echo $picName
curl $picPath -o $HOME/Pictures/Background/$picName
相关文章推荐
- Shell之实现多线程
- 常用shell命令
- shell 生成数组
- shell教程-002:常见的Shell种类
- shell教程-001:shell简介 什么是shell,shell命令的两种执行方式
- Bash 的 shopt extglob ( 用来删除指定文件以外的文件,反向删除)
- PowerShell学习的一小步,工作的一大步
- Shell脚本(自动填充函数模板)
- bash中单引号、双引号、反单引号等的区别
- Linux Shell 使用技巧
- Linux bash 扩展
- shell(一)
- shell爬虫
- 文章标题
- shell日期的应用
- linux上java调用shell脚本
- shell切割日志脚本
- Bash脚本编程变量浅谈
- 深入浅出Shell编程 Shell变量介绍
- shellcode学习总结