Skip to content Skip to sidebar Skip to footer

How To Pass A Password With Quotes And Single Quotes In Terminal?

I created a .keystore for my Android application, generating a random password. It contains quotes (') and singles quotes (') in the same password, like this one: xxxxxx'xxx!\x='x

Solution 1:

If you don't know what history expansion is, you don't use it, or you don't know whether you use it, append set +H to your .bashrc to disable it. This will stop interactive bash sessions from messing with your otherwise well placed exclamation marks.

You can also just run set +H from your prompt to disable it for that session:

$ echo"!foo"
bash: !foo: event not found

$ set +H
$ echo"!foo"
!foo

Alternatively, you can work around it by putting exclamation marks in single quotes:

$ echo"fo'o!ba\\r"
bash: !ba\\r: event not found

$ echo"fo'o"'!'"ba\\r"
fo'o!ba\r

Here the double quoted string is used as is, but the ! is replaced by "'!'" which closes the double quotes, starts a single quoted segment, adds the !, then closes the single quotes and opens a double quoted string again.

Solution 2:

I would stick the password into a variable

pass='xxxxxx"xxx!\x='\''x'

The '\'' bit is one way to embed a single quote into a single quoted string in bash.

Then you can just use the variable in double quotes

cmd -p "$pass"

Solution 3:

Unfortunately I guess you have to escape the special characters, like this:

xxxxxx\"xxx\\!xx\'x

Post a Comment for "How To Pass A Password With Quotes And Single Quotes In Terminal?"