Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to set an environment variable containing the URL of my proxy server with my credentials, as in this blog post.

The problem I'm having is that my password contains an at symbol and I am not sure how to properly escape it:

SET HTTP_PROXY=http://username:p@assword@proxy.yourdomain.com:8080

How do I do this?

By the way, I realize setting an environment variable containing my credentials is a Very Bad Idea. I'm open to other suggestions that would allow me to use composer behind an authenticated proxy if anyone has one.

share|improve this question
    
You haven't made it clear that you're talking about URI "escaping", not command interpreter escaping. Which is why you're getting these answers about command interpreter escaping. –  JdeBP Jan 15 at 21:48
    
Sorry, I meant URI escaping. –  Koveras Jan 15 at 22:46

2 Answers 2

up vote 1 down vote accepted
set HTTP_PROXY=http://username:p^%40assword@proxy.yourdomain.com:8080
  1. One needs to percent encode the @ in the password as %40, because @ is a delimiter.
  2. One needs to escape the % in the set command so that the command interpreter doesn't even attempt to perform environment variable substitution. The ^ character as an escape character is a convention that has been around from as far back as IBM's/Microsoft's cmd for OS/2 1.x, and that is supported in Microsoft's cmd on Windows NT — as well as in command interpreters such as TCC/LE — to this day.
share|improve this answer

Special characters can be escaped with "^" on the Windows CMD Shell. So:

SET HTTP_PROXY=http://username:p^@assword^@proxy.yourdomain.com:8080

would be outputted as:

C:\>echo %HTTP_PROXY%
http://username:p@assword@proxy.yourdomain.com:8080

on the shell. But that depends on the tool that is using the variable, I don't know for sure if git takes this as input correctly (but I think so).

share|improve this answer
    
I guess what I'm confused about is how it can tell the difference between the first at sign and the second, or does it not matter? –  Koveras Jan 15 at 18:54
    
It does not matter, the '^' just escapes the following character. Every time - so ^^.^^ will work too (output: ^.^). –  bjoster Jan 16 at 19:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.