Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to escape the '@' symbol in bash?

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 [email protected].

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.

like image 247
jobin Avatar asked Nov 11 '13 08:11

jobin


People also ask

How do I ignore special characters in Bash?

Note the % <percent-sign> character within the printf argument. We can ignore its special meaning by escaping it with another <percent-sign>: %%. This preserves the literal value.

How do I escape a character in a shell script?

The escape (\) preceding a character tells the shell to interpret that character literally. With certain commands and utilities, such as echo and sed, escaping a character may have the opposite effect - it can toggle on a special meaning for that character.

How do I escape a character in Unix?

z/OS UNIX System Services User's GuideAll escape sequences are made from a backslash character ( \ ) followed by one to three other characters. Escape sequences are used inside strings, not just those for printf, to represent special characters. In particular, the \n escape sequence represents the newline character.

How do you escape a colon in Bash?

In bash ; escape with '\'. You do not need to escape the colon; assuming the variable values are correct, quoting the expansions is the only thing that may make a difference.


1 Answers

You can use %40 instead of an @ sign.

like image 200
David Schwartz Avatar answered Oct 07 '22 19:10

David Schwartz