Retrieve pass store secrets in Python, Bash and Perl scripts

(, en)

One of the major advantages of Pass: The Standard Unix Password Manager is its interoperability. You can basically call it from anywhere. Basically also means that there might be a catch: I use the ncurses version of pinentry on the console. If you call pass from a script it needs to be able to start pinentry and show the dialog to enter the passphrase for the password store. Here are my snippets to get it working in Bash, Python and Perl:


PASS_FIRST=$(pass show secret | head -n 1)
echo ">>$PASS_FIRST<<"

PASS_MULTI=$(pass show secret)
echo ">>>"
echo "$PASS_MULTI"
echo "<<<"


(Python was more tricky than expected, but this works)

import subprocess as sp

res = ("pass show secret", shell=True, stdout=sp.PIPE)
    .stdout.decode("utf-8", "replace")


use warnings;
use utf8;
use 5.30.0;

my $pass = qx#pass show secret#;
$pass = (split /\n/, $pass)[0];
say ">>$pass<<";