How to quote a variable inside wget command

238 Views Asked by At

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`

enter image description here

but I'm trying to extract the token, and run a shell script as below:

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: enter image description here

wget version: 1.14

Does anyone have a clue to solve this problem~?

1

There are 1 best solutions below

0
On

finally figure out the reason by wget -d: delete the apostrophe around the header and it works fine for me.

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