加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 在bash中设置wget –header =不起作用

发布时间:2020-12-13 18:50:58 所属栏目:Linux 来源:网络整理
导读:我试图在wget中设置标题.当我在终端中运行以下命令时,它工作wget -d –header =“用户代理:Mozilla / 5.0( Windows NT 6.0)AppleWebKit / 537.11(KHTML,如Gecko)Chrome / 23.0.1271.97 Safari / 537.11”’http ://website.com -O index 但是,一旦我在变量
我试图在wget中设置标题.当我在终端中运行以下命令时,它工作wget -d –header =“用户代理:Mozilla / 5.0( Windows NT 6.0)AppleWebKit / 537.11(KHTML,如Gecko)Chrome / 23.0.1271.97 Safari / 537.11”’http ://website.com -O index

但是,一旦我在变量中添加相同的内容并尝试运行bash脚本,它就无法正常工作.

我试过的

header='-d --header="User-Agent: Mozilla/5.0 (Windows NT 6.0) AppleWebKit/537.11 (KHTML,like Gecko) Chrome/23.0.1271.97 Safari/537.11"'
wget "$header" http://google.com -O index

错误

wget: invalid option -- ' '
wget: invalid option -- '-'
wget: invalid option -- '-'
Usage: wget [OPTION]... [URL]...

解决方法

使用变量时必须使用双引号.否则它将扩展为多个单词.另一方面,不需要引用变量值两次.以下应该有效:
header='--header=User-Agent: Mozilla/5.0 (Windows NT 6.0) AppleWebKit/537.11 (KHTML,like Gecko) Chrome/23.0.1271.97 Safari/537.11'
wget "$header" http://website.com -O index

编辑:如果要为多个参数使用变量,请使用数组:

args=(-d '--header=User-Agent: Mozilla/5.0 (Windows NT 6.0) AppleWebKit/537.11 (KHTML,like Gecko) Chrome/23.0.1271.97 Safari/537.11')
wget "${args[@]}" http://website.com -O index

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读