0

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

I am trying to pass the password using keytool. How can I pass the password?

keytool -list -storepass "<my_password>" -keystore my.keystore

And shows:

-bash: !\xx'x": event not found

Thanks!

EDIT I tried using:

keytool -list -storepass xxxxxx\"xxx\!x=\'x -keystore my.keystore

keytool error: java.io.IOException: Keystore was tampered with, or password was incorrect

Javier S.
  • 756
  • 8
  • 9

3 Answers3

0

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

xxxxxx\"xxx\\!xx\'x

samgak
  • 23,944
  • 4
  • 60
  • 82
Davison
  • 71
  • 3
0

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.

that other guy
  • 116,971
  • 11
  • 170
  • 194
  • Thanks a lot! I can use echo "xxxxxx"xxx"'!'"\x='x" and it shows the password. But then I pass the same in _-storepass_ for keytool and it continues showing the same error message. Maybe keytool uses some weird algorithm? – Javier S. Apr 13 '15 at 22:12
  • What you posted appears to be missing a quote so it can't be used, and your edit shows a distinctly different error message than the "event not found" you had before, and indicates that you're using the wrong password. You have to keep in mind that unescaped quotes are shell syntax and are not passed to keytool, so if you input `foo"bar"` as a password while running keytool (as opposed to when starting keytool), specifying `-storepass foo"bar"` will not work (instead, you'd have to use something like `-storepass 'foo"bar"'`) – that other guy Apr 13 '15 at 22:46
0

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"
glenn jackman
  • 238,783
  • 38
  • 220
  • 352