无法通过变量内的引号传递wget变量 [英] unable to pass wget a variable with quotes inside the variable

查看:77
本文介绍了无法通过变量内的引号传递wget变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写wget命令脚本来下载网页及其所有附件和jpeg等.

I am trying to script a wget command to download a web page and all it's attachments and jpegs etc.

当我手动输入脚本时,它可以工作,但是我需要运行35000次以上才能存档一个旧网站,该网站不受我的控制(国际公司政策,但我是数据的所有者)

When I enter the script by hand, it works, but I need to run this over 35000 times to archive an old web site which is outside of my control (international company politics, but I'm the owner of the data).

我的问题一直在于会话参数的可变性.

My problem has been in variablising the session parameters.

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

My script so far is as follows:

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

但是当我运行脚本时,我得到以下输出

but when I run the script, I get the following output

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.

如您所见,主机"和"Cookie"部分的格式不正确,导致wget命令无法登录并提取数据.

As you can see, the Host and Cookie sections are not being properly formatted, resulting in the wget command failing to log in and extract the data.

我一直在阅读bash手册页,谷歌搜索,并尝试过SO的一些相关建议,但是我仍然无法获得要执行的命令.

I've been reading the bash man pages, googling, and have tried several related suggestions from SO, but I'm still unable to get the command to execute.

外面有谁能很好地向我展示引用实物报价的正确方法?

Anyone out there going to be nice enough to show me the correct way to quote quotes in veriables?

谢谢

推荐答案

带引号的字符串或变量内的引号是普通字符,而不是引号.没有办法改变它.改用数组:

Quotes inside of quoted strings or variables are ordinary characters, not quoting characters. There's no way to change that. Use an array instead:

A=(a b 'c d' 'e f')
cmd "${A[@]}"

用四个参数abc de f调用cmd.

calls cmd with four arguments a, b, c d, and e f.

(您可以通过eval达到类似的效果,但这更容易出错.在您的情况下,使用数组要方便得多.)

(You could achieve a similar effect with eval, but that's a lot more error prone. In your case, using arrays is much more convenient.)

这篇关于无法通过变量内的引号传递wget变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆