Score:0

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
Score:1
cn flag

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

printf "bot\nn\nJava" | ./questions.sh

Or use expect like so:

#!/usr/bin/expect -f

set timeout -1
spawn ../4/questions.sh

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 https://www.baeldung.com/linux/bash-interactive-prompts

Tlink avatar
ao flag
Thank you @ttsakpc , what about selections in screens like this one? https://images.app.goo.gl/uwRDDpBPkN3JxeGk8
ttsakpc avatar
cn flag
I believe that it should also work with `expect`. If not you can try `empty-expect` as mentioned here https://stackoverflow.com/questions/66199156/how-can-i-make-a-bash-inputmenu-dialog-start-with-rename-automatically-clicked
mangohost

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.