0

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.

1
  • 1
    Without the script source we hardly can help you May 18, 2022 at 12:05

1 Answer 1

1

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

2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .