top of page

Shell script to ask for favourite colour with a time limit

Interact with users while enforcing time limits in shell scripts.

Linux bash script allows you to accept user inputs within the time limit and read what user types on the screen. This is achieved by Linux read with -t command within the script. In the below script, we will be asking users their favorite color and the user has to enter within 5 seconds and prompt the user with the input they have typed on the screen else exit from the script.

vi favourite_color.sh
# !/bin/bash

read -t 5 -p "Type your favorite color: " color
echo $color

Here is the sample output of the above script.

shell script to ask for favourite colour with a time limit

More ways to use a time limit Input Bash Script

  • We can set a time limit for the password section, if the user delay entering the password then the user will exit from the login.

  • You use a time limit with a quiz where the user has to answer the question within time.

Become a top notch dba with DBA Genesis
Start your DBA career today
bottom of page