export USER_PROXY= "proxy.zyz.com:122"
- You can't have a space here. This sets
USER_PROXY
to an empty string and tries to export a non-existant variable 'proxy.zyz.com:122'. You probably want
export USER_PROXY="proxy.zyz.com:122"
jq -r --arg UPROXY ${USER_PROXY} '.proxies = {
"default": {
"httpProxy": "http://$UPROXY\",
"httpsProxy": "http://$UPROXY\",
"noProxy": "127.0.0.1,localhost"
}
}' ~/.docker/config.json > tmp && mv tmp ~/.docker/config.json
- You need quotes around
${USER_PROXY}
otherwise any whitespace in it will break it. Instead use --arg UPROXY "${USER_PROXY}"
.
- This isn't the syntax for using variables inside a string in jq. Instead of
"...$UPROXY..."
you need "...\($UPROXY)..."
- You are escaping the
"
at the end of the string by putting a \
before it. I am not sure what you mean here. I think you perhaps meant to use a forward slash instead?
This last issue is the immediate cause of the error message you're saying. It says "syntax error, unexpected IDENT, expecting '}' at line 4"
and then shows you what it found on line 4: "httpsProxy": ...
. It parsed the string from line 3, which looks like: "http://$UPROXY\"\n "
because the escaped double quote doesn't end the string. After finding the end of the string on line 4, jq expects to find a }
to close the object, or a ,
for the next key-value-pair, but it finds httpsProxy
, which looks like an identifier. So that's what the error message is saying. It found an IDENTifier when it was expecting a }
(or a ,
but it doesn't mention that).