Expect

expect(1) is a tool and scripting language for automating interactive command line tools.

Contents

  1. Expect
    1. Example


Example

Consider the age(1) encryption tool, which supports passphrase (symmetric key) encryption but does not support passing the passphrase in plain text.

$ tar -c example.txt | age --encrypt --passphrase > example.tar.age
Enter passphrase (leave empty to autogenerate a secure one):
Confirm passphrase:

To automate this exchange, try:

expect <<EOF
spawn sh -c "age --encrypt --passphrase example.tar > example.tar.age"
expect "*:"
send "test123\r"
expect "*:"
send "test123\r"
expect eof
EOF


CategoryRicottone