0

I would like to retrieve a password from a Keepass database using keepassxc-cli within a (backup) shell script. (For security purposes it would rather not save it within a text file on my file system.) The required command looks like this:

/Applications/KeePassXC.app/Contents/MacOS/keepassxc-cli show -a Password --key-file=/path/to/keyfile /path/to/database.kdbx "/path/to/entry/within/database"

When entering this command manually on my terminal, I get prompted for my master password and then, after entering this master password, the referenced password is shown on the next line:

Enter password to unlock /path/to/database.kdbx: <me_entering_my_master_password>
TESTPASSWORD

The relevant part of my script looks like this (whereby the aforementioned command is stored as a string in KEEPASSCMD and I'm just echoing for debugging purposes):

REPOPASSWORD=$(eval $KEEPASSCMD)
echo $REPOPASSWORD

When running the script, however, I don't get prompted to enter my master password but instead nothing is shown on the terminal. After "blindly" entering my master password, the following output is shown:

Enter password to unlock /path/to/database.kdbx: TESTPASSWORD

That is, the prompt is stored within REPOPASSWORD, too. Is it somehow possible to exclude the prompt, so only the string TESTPASSWORD gets stored in REPOPASSWORD?

mamr
  • 63
  • 5

1 Answers1

0

Which shell are you using? Your code works for me both on bash and zsh with keepassxc 2.6.2. Have you tried without eval?

REPOPASSWORD=$(/Applications/KeePassXC.app/Contents/MacOS/keepassxc-cli show -a Password --key-file=/path/to/keyfile /path/to/database.kdbx "/path/to/entry/within/database")
echo $REPOPASSWORD
iliis
  • 878
  • 8
  • 19