I want to create a simple script that initiates a simple gui-based program (think ncurses-style, text-based graphics in a shell) in Debian. I only access the server through SSH, so I can't do standard macros or anything.

The input is always the same: I just need it to start the program, then within the context of the program, send an "enter" keystroke, an "R" keystroke, and an "F7" keystroke.

I've been working on this for a while now, and I can't seem to figure anything out. Is there any way to do this within a bash script?

Thank you and have a good day

  • 1
    expect could work for that. – Bobby Jul 22 '12 at 11:58

This seems very similar to a recent question.


read -n 1 x; while read -n 1 -t .1 y; do x="$x$y"; done

But as mentioned in that thread, using dialog or similar scripting menuing programs would be the better option.

Or...are you wanting to send those keystrokes to a program? If so, you probably want to use expect.

  • I am trying to send the input TO a program. I.E. I want to automatically run the binary, which opens the text gui. I then want the program to automatically start based on the static keypresses that occur within the context of the program. – user115360 Jul 22 '12 at 4:51
  • @user115360: So then expect is what you want. – Seth Robertson Jul 22 '12 at 12:19

This would do:

[root@w4n-dl-c60-64-yannick ~]# cat test.sh
echo "The year is: $var_year"
read var_year

echo -n "Enter your name and press [ENTER]: "
read var_name
echo "Your name is: $var_name"

echo "You are $((2012 - $var_year)) years old!"
echo "You can go on!...."
read var_con
[root@w4n-dl-c60-64-yannick ~]# ./test.sh
The year is:
Enter your name and press [ENTER]: Yannick
Your name is: Yannick
You are 32 years old!
You can go on!....

[root@w4n-dl-c60-64-yannick ~]#
  • This doesn't seem to work with binaries. I need to script static input to occur at set points according to a binary's prompts. – user115360 Jul 20 '12 at 20:11
  • Anyone else have a suggestion? – user115360 Jul 21 '12 at 5:58

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.