Celeb Glow
general | February 28, 2026

read command with timeout for non-terminal input in bash

The read command in bash is used for user input. Option -t N invokes the timeout of N seconds. But, as mentioned in the man page,

This option has no effect if read is not reading input from the terminal or from a pipe.

But this is exactly what I need - I need a script that is launched via desktop shortcut (not from terminal), and should wait another second for a single key to decide further actions. How can I make bash script wait a bit for user input in this case?

1

1 Answer

Use timeout command before the read command.

Syntax:timeout [OPTION] NUMBER[SUFFIX] COMMAND [ARG]...

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy