8

I am trying to add my proxy with authentication parameters in bash, where my password contains an @ symbol. The syntax to add proxy with authentication in bash is as follows:

export http_proxy=http://username:password@host:port_no/

Therefore, whenever I try to add a password with @ in it, the applications that use this proxy try to connect to the string followed by the @ symbol in the password.

For example, if my password is p@ssword, and the host is proxy.college.com, the applications try to connect to ssword@proxy.college.com.

I have tried escaping the @ symbol using \, but this does has not solved. How do I make this work without changing my password?

Note: This question is not similar to How can i escape an arbitrary string for use as a command line argument in bash nor How to escape the at sign in bash since this specifically treats the '@' sign that comes up in commands where there is an @ symbol already present and the @ is used to delimit the given string into specific paramters.

P.S.: Though using the HTML code %40 for @ works, I would prefer a more readable method.

Community
  • 1
  • 1
jobin
  • 2,600
  • 7
  • 32
  • 59
  • 2
    I'd change my password ;-) – hgoebl Nov 11 '13 at 08:35
  • Isn't that an unclean way of doing this? – jobin Nov 11 '13 at 08:40
  • Why do you need to write your login password that way? What application forces you to do that? it's probably a terrible security issue. Please read the `man` page of the application you're using, check that there's a possibility to send the password differently, or otherwise switch to another application. – gniourf_gniourf Nov 11 '13 at 08:41
  • Yes, I accept its a security issue, but most, including `apt-get` applications need the username and passwords in `/etc/apt/apt.conf` files. Others take it from the environment variables specified in `/etc/environment` or in `/home/$USER/.bashrc`. Though not a part of this question, I would readily accept other known, secure ways of doing this. – jobin Nov 11 '13 at 08:46
  • This is not a question about the shell (which does not require `@` to be escaped in this context), but about whatever program is using the `http_proxy` variable. If HTML encoding is the only way to get it to accept a literal `@`, that's what you'll have to do. – chepner Nov 11 '13 at 13:29

1 Answers1

8

You can use %40 instead of an @ sign.

David Schwartz
  • 179,497
  • 17
  • 214
  • 278
  • My bad, I forgot to mention I wouldn't prefer using HTML codes, isn't there a way to escape this? – jobin Nov 11 '13 at 08:35