How to pass argument with exclamation mark on Linux?


How to pass argument with exclamation mark on Linux?

I have a simple Python script that receives username and password as arguments, but my password contains two exclamation marks. When I call my script like
salafek@dellboy:~/Desktop/$ -u username -p pass!!

a command that I entered earlier replaces the exclamation marks:
salafek@dellboy:~/Desktop/$ -u username -p “ -u username -p passwget wget”

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


Solution 1:

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

$ -u username -p 'pass!!'

Solution 2:

You need to escape it with \ or quote it with single quotes, otherwise your shell interprets it. -u username -p pass\!\!

or -u username -p 'pass!!'

Solution 3:

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: -u 'username' -p 'pass!!'

Solution 4:

Have you tried

$ -u username -p "pass!!"

EDIT- This won’t work. Read comments below