如何在Bash变量中存储eval的结果时省略用户提示



我想在(备份(shell脚本中使用keepassxc-cli从Keepass数据库中检索密码。(为了安全起见,它宁愿不将其保存在我的文件系统上的文本文件中。(所需的命令如下:

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

当在我的终端上手动输入此命令时,我会被提示输入我的主密码,然后,在输入此主密码后,引用的密码显示在下一行:

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

我的脚本的相关部分如下(其中前面提到的命令作为字符串存储在KEEPASSCMD中,我只是为了调试目的而回显(:

REPOPASSWORD=$(eval $KEEPASSCMD)
echo $REPOPASSWORD

然而,在运行脚本时,不会提示我输入主密码,而是在终端上什么都不显示。在"盲目"输入我的主密码后,显示以下输出:

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

也就是说,提示也存储在REPOPASSWORD中。是否可以以某种方式排除提示,从而只有字符串TESTPASSWORD存储在REPOPASSWORD中?

您使用的是哪个shell?您的代码在bash和使用keepassxc2.6.2的zsh上都适用。你试过不用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

最新更新