Selecting cli menu options from my bash script

ao flag

I'm running a bash script but the process freezes when it hit a menu where it have to make a selection I understand that for YES ican use -y in my commands, but in the case where:

  1. I need to select/enter a number from an options list

  2. Enter a name or an email

How can I do that?

Weird enough that most of the search results return how to create a menu using bash, but not how to make a script enter selections/values.

Romeo Ninov avatar
in flag
Without the script source we hardly can help you
cn flag

You could just pipe a text with the answers to the command:

printf "bot\nn\nJava" | ./

Or use expect like so:

#!/usr/bin/expect -f

set timeout -1
spawn ../4/

expect "Your name: "
send -- "expect\n"

expect "Are you human?\r
y/n: "
send -- "n\r"

expect "What is your favorite programming language?\r
Your answer: "
send -- "Java\r"

expect eof

more info here

Tlink avatar
ao flag
Thank you @ttsakpc , what about selections in screens like this one?
ttsakpc avatar
cn flag
I believe that it should also work with `expect`. If not you can try `empty-expect` as mentioned here

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.