Windows – Set environment variable containing at symbol

authenticationcommand lineenvironment-variablesPROXYwindows 7

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.

Best Answer

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.
Related Question