How to escape ! in password?

Posted on

How to escape ! in password? – A server stack is the collection of software that forms the operational infrastructure on a given machine. In a computing context, a stack is an ordered pile. A server stack is one type of solution stack — an ordered selection of software that makes it possible to complete a particular task. Like in this post about How to escape ! in password? was one problem in server stack that need for a solution. Below are some tips in manage your linux server when you find problem about linux, mysql, bash, , .

How might one escape the exclamation point in a password:

$ mysql -umyuser -pone_@&!two
-bash: !two: event not found

Trying the obvious backslash did not help:

$ mysql -umyuser -pone_@&!two
[1] 22242
-bash: !two: command not found [~]# ERROR 1045 (28000): Access denied for user 'myuser'@'localhost' (using password: YES)

All my google searches suggest that the backslash would help, but it does not. There is no way to use quotes as suggested in this question. The line will be used in a .bashrc alias. Don’t worry, the usernames and passwords shown here are examples only and not used in production!

Use single quotes around the password like this: -p'one_@&!two'

To put it in an alias, you’d do something like:

alias runmysql='mysql -umyuser -p'''one_@&!two''''

-bash: !two: command not found

You also need to escape the & character:

$ mysql -umyuser -pone_@&!two

If you never use the ! history features, it might be more convenient to simply disable them (with set +H in your bashrc).

You can store the password in a bash variable:

$ pass='one_@&!two'

Then substitute the variable in the command:

$ mysql -umyuser -p$pass

Leave a Reply

Your email address will not be published.