shell腳本讀取文件+讀取命令行參數+讀取標准輸入+變量賦值+輸出到文件


讀取url_list文件批量下載網頁

url_list

http://www.tianyancha.com/company/2412078287
http://www.4399.com/special/1.htm
http://www.we7.cc/
http://kongzhong.tmall.com/
http://dianying.2345.com/
http://www.takefoto.cn/viewnews-1521788.html
http://www.x4jdm.com/bf/429-1-1.html
http://www.douyu.com/546715
http://www.zjedu.gov.cn/default.html
http://dl.xunlei.com/

 download.sh

#!/bin/bash
for line in $(cat $1)
do
    id=$(echo $line| getid | awk '{$id=10000+$1;print $id;}')
    echo $line | gethtmlfile $id > "./result/"${id}".html"
done

運行:

[spider@zhangsuosheng]$ chmod +x ./download.sh 
[spider@zhangsuosheng]$ ./download.sh url_list

 

 1、sh文件格式

http://www.runoob.com/linux/linux-shell.html

 

 

2、bash按行讀取文件+bash讀取命令行參數

測試文件:url_list_zss

[spider@zhangsuosheng]$ cat url_list_zss 
cccccc
ddddddddd
aaaaaa

正確寫法:

#!/bin/bash
for line in $(cat $1)
do
    echo $line
done
[spider@zhangsuosheng]$ chmod +x ./download.sh 
[spider@zhangsuosheng]$ ./download.sh url_list
cccccc
ddddddddd
aaaaaa

不合適的寫法:

#!/bin/bash
for line in 'cat $1'
do
        echo $line
done
[spider@zhangsuosheng]$ chmod +x ./download_testhtml.sh 
[spider@zhangsuosheng]$ ./download_testhtml.sh url_list_zss 
cat $1

https://www.jb51.net/article/122918.htm

 

3、讀取命令行參數

https://blog.csdn.net/qq_30145093/article/details/78191941

https://blog.csdn.net/ruidongliu/article/details/9717905


 4、加法運算

用的awk

 

 

5、讀取管道中的標准輸入 直接讀/xargs

https://www.cnblogs.com/wangqiguo/p/6464234.html

 

6、變量賦值

https://blog.csdn.net/lemontree1945/article/details/79126819

 

7、字符串拼接

https://www.jb51.net/article/44207.htm


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM