tags:

views:

98

answers:

6

I have simple python script that receive username and password as argument. But my password contains two exclamation marks.When i call script:

salafek@dellboy:~/Desktop/$ emailsender.py -u username -p pass!!

command that I enter earlier replace exclamation marks

salafek@dellboy:~/Desktop/$emailsender.py -u username -p "passemailsender.py -u username -p passwget wget http://www.crobot.com.hr/templog"

I can escape exclamation marks with backslash(\) but my password changes. Is there solution for this, how can I escape exclamation marks without changing password?

A: 

Have you tried

$ emailsender.py -u username -p "pass!!"

EDIT- This won't work. Read comments below

Infinity
double quotes won't help
unbeli
Double/single quotes, would both work the same in this example. The difference is that single quotes don't expand $VARIABLES, and double quotes do. http://www.mpi-inf.mpg.de/~uwe/lehre/unixffb/quoting-guide.html
Infinity
@Infinity - "!!" is a variable in bash, though, so single quotes are required.
Joe Kington
I should've known that.. thanks
Infinity
A: 

You can try python raw strings. You put a 'r' in the beginning of the quoted string to make it raw.

See here http://docs.python.org/release/2.5.2/ref/strings.html

theproxy
+3  A: 

You should be able to simply wrap things in single quotes in the shell.

$ emailsender.py -u username -p 'pass!!'
Joe Kington
+3  A: 

You need to escape it with \ or quote it with single quotes, otherwise your shell interprets it.

emailsender.py -u username -p pass\!\!

or

emailsender.py -u username -p 'pass!!'
unbeli
+1  A: 

As mentioned by others, this issue isn't specific to Python, but is caused by how you're passing the password parameter to the script.

You'll want to wrap the password string in single quotes to make sure that it's passed to the script exactly as you type it, and isn't interpreted by the shell.

You could do this for the username too, if there's the possibility that it includes an exclamation mark, or other special character.

For example:

emailsender.py -u 'username' -p 'pass!!'
EdoDodo
A: 

solution is to escape password using single quotes ,
thanks to everybody especially to Joe and @unbeli

salafek