1

In Bash, how can I ask for user input while I'm processing data from stdin? In this case, the read or select commands do not work. E.g.:

while read line
do
    # process line
    echo "Do you want to continue? [y/n]"
done
3
  • did you tried using read ? Commented Jun 17, 2014 at 5:58
  • read -p "Do you want to continue? [y/n]" ans Commented Jun 17, 2014 at 5:59
  • @Arvind Of course, but this doesn't work. In the example, the read command would return immediately without waiting for user input. Commented Jun 17, 2014 at 6:44

1 Answer 1

2

Perhaps read with its stdin redirected from /dev/tty should help

Untested code (see tty(4) about /dev/tty):

read -p "Continue? [y/n]: " yn < /dev/tty
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.