I've written a script to handle quick copying of passwords to the clipboard:

#!/usr/bin/expect -f

spawn -noecho zsh
expect "$ "
send "pass show -c "

This script is launched like this:

urxvt -e /home/user/pass_script.sh

The script runs well, but after finishing, the spawned urxvt terminal needs to close. It doesn't do so as of now. How can I make sure it does?

  • 1
    does it auto close for other commands like urxvt -e sleep 5? if yes, try urxvt -e expect -d /home/user/pass_script.sh and see what's the problem.
    – pynexj
    Nov 27, 2018 at 13:51
  • That code is fine. The problem, I'm guessing, is what the pass command does after you hit enter. Does it ever end? Nov 27, 2018 at 18:14
  • @pynexj: yes, it does close after running urxvt -e sleep 5. running with debug flag doesn't show me what goes wrong; the script will just copy my password to clipboard and return with a new prompt (instead of exiting). @glenn jackman: well, I have to add my desired password ID after the already entered "pass show -c ". After entering my ID, zsh will return with a prompt instead of exiting. Nov 27, 2018 at 18:38
  • just replace interact with expect "$ "
    – pynexj
    Nov 28, 2018 at 3:36

1 Answer 1


This works:

#!/usr/bin/expect -f
set timeout -1
spawn -noecho bash
expect "$ "
send "pass show -c " 
interact -nobuffer \r return
expect "Copied"
sleep 0.05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.