简体   繁体   English

如何在 wget 命令中引用变量

[英]How to quote a variable inside wget command

The command runs well below:该命令在下面运行良好:

wget --header 'Authorization: token GIT_PERSONAL_ACESS_TOKEN' https://raw.githubusercontent.com/.../.../main/repo/packages/.../file.txt -P /opt/tomcat`

在此处输入图像描述

but I'm trying to extract the token, and run a shell script as below:但我正在尝试提取令牌,并运行 shell 脚本,如下所示:

read -p "pls input the token:  " token
echo "print out my token: ${token}"
header="Authorization: token ${token}"
header=\'$header\'
echo "print out my header: ${header}"
wget --header "${header}" https://raw.githubusercontent.com/.../.../main/repo/packages/.../file.txt  -P /opt/tomcat 

and I gain the 404 Not Found Respond:我得到 404 Not Found 响应:在此处输入图像描述

wget version: 1.14 wget版本:1.14

Does anyone have a clue to solve this problem~?有没有人有解决这个问题的线索~?

finally figure out the reason by wget -d: delete the apostrophe around the header and it works fine for me.最后通过 wget -d 找出原因:删除 header 周围的撇号,它对我来说很好用。

enter image description here在此处输入图像描述

read -p "Input the token: " token
wget -d --header "Authorization: token ${token}" https://raw.githubusercontent.com/.../.../main/repo/packages/.../file.txt  -P /opt/tomcat 

enter image description here在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM