期望在 bash 调试中看到响应,但我无法得到它。

expect response seen in bash debug but I cant get it.

我正在尝试从 keepass 数据库中获取信息,但我无法通过这最后一步!

#!/usr/bin/env bash
#!/usr/bin/expect

firewall=
password="PASSWORD"
echo "connecting to KeepassDB..."

function get_creds {
expect <<- DONE
    set timeout 10
    spawn kpcli
    match_max 100000000
    expect  "kpcli:/>"
    send    "open /media/sf_VM_shared/keepass.kdb\n"
    expect  "password:"
    send    "$password\n"
    expect  ">"
    send    "cd General/Network/Firewalls/SSH\n"
    expect  "SSH>"
    send    "ls\n"
    expect  ">"
DONE

}


credentials=$(get_creds)
echo $credentials 

当我执行 bash -x 时,我可以看到我想要的,这是一长串信息,但没有 -x 脚本不会将列表返回到终端。

使用 bash -x 时会得到输出,因为每个命令输出都会在 运行(调试模式)

之后打印

脚本不打印,因为 get_creds 的最后一行输出为空。它应该打印方法输出的最后一行。

当使用 echo 输出您的凭据时,您应该使用引号 (") 以保留换行符。

尝试将脚本中的最后一行替换为:

echo "$credentials"