无法通过variables内部的引号传递wgetvariables

我想编写一个wget命令来下载一个网页,所有的附件和jpeg等

当我手动input脚本的时候,它是有效的,但是我需要运行这个35000次来存档一个不受我控制(国际公司政治,但我是数据所有者)的旧网站。

我的问题一直在变化会话参数。

我的脚本到目前为止如下:

cnt=35209 # initialise the headers general_settings='-4 -P xyz --restrict-file-names=windows -nc --limit-rate=250k' html_page_specific='--convert-links --html-extension' proxy='--proxy-user=xxxxxx --proxy-password=yyyyyyy' session="--header=\'Host: mywebsite.com:9090\' --header=\'User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:20.0) Gecko/20100101 Firefox/20.0\'" address=http://mywebsite.com:9090/browse/item-$cnt echo $general_settings $proxy $session $cookie $address echo echo echo Getting item-$cnt... #while [ $cnt -gt 0 ] #do # # get the page wget --debug $general_settings $html_page_specific $proxy $session $cookie $address # now get the attachments, pdf, txt, jpg, gif, sql, etc... # wget -A.pdf $general_settings -r $proxy $session $cookie $address # wget -A.txt $general_settings -r $proxy $session $cookie $address # wget -A.jpg $general_settings -r $proxy $session $cookie $address # wget -A.gif $general_settings -r $proxy $session $cookie $address # wget -A.sql $general_settings -r $proxy $session $cookie $address # wget -A.doc $general_settings -r $proxy $session $cookie $address # wget -A.docx $general_settings -r $proxy $session $cookie $address # wget -A.xls $general_settings -r $proxy $session $cookie $address # wget -A.xlsm $general_settings -r $proxy $session $cookie $address # wget -A.xlsx $general_settings -r $proxy $session $cookie $address # wget -A.xml $general_settings -r $proxy $session $cookie $address # wget -A.ppt $general_settings -r $proxy $session $cookie $address # wget -A.pptx $general_settings -r $proxy $session $cookie $address # wget -A.png $general_settings -r $proxy $session $cookie $address # wget -A.ps $general_settings -r $proxy $session $cookie $address # wget -A.mdb $general_settings -r $proxy $session $cookie $address # ((cnt=cnt-1)) # #done 

但是当我运行脚本时,我得到了下面的输出

 Getting item-35209... Setting --inet4-only (inet4only) to 1 Setting --directory-prefix (dirprefix) to xyz Setting --restrict-file-names (restrictfilenames) to windows Setting --no (noclobber) to 1 Setting --limit-rate (limitrate) to 250k Setting --convert-links (convertlinks) to 1 Setting --html-extension (htmlextension) to 1 Setting --proxy-user (proxyuser) to xxxxx Setting --proxy-password (proxypassword) to yyyyy Setting --header (header) to \'Host: Setting --header (header) to 'Cookie: DEBUG output created by Wget 1.11.4 Red Hat modified on linux-gnu. 

如您所见,Host和Cookie部分的格式不正确,导致wget命令无法login并提取数据。

我一直在阅读bash手册页,search,并尝试了几个相关的build议,但我仍然无法得到执行的命令。

任何人都会很好地向我展示正确的方式来引用可靠的报价?

谢谢,

带引号的字符串或变量内的引号是普通字符,不是引号字符。 没有办法改变这一点。 使用数组来代替:

 A=(ab 'cd' 'e f') cmd "${A[@]}" 

用四个参数abcdef调用cmd

(你可以用eval实现类似的效果,但是这更容易出错,在你的情况下,使用数组更方便。)

 session="--header=Host: mywebsite.com:9090 --header=User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:20.0) Gecko/20100101 Firefox/20.0" 

用这个,