• Arun Kumar

Shell script to ask for favourite colour with a time limit

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.


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.

6 views

Recent Posts

See All

Basic Linux Commands

This article describes basic Linux commands that you must know as a system or database administrator. Below commands in Linux help you manage any Linux server fast and smoothly. Linux Command List Che

Linux Firewall with iptables and firewalld

In this article will be covering details regarding iptables and firewalld which helps in Linux firewall management. We will also be looking at how to enable specific ports (1521 for Oracle) inside ipt

Passwordless SSH in Linux

Every time you ssh from one Linux server to another, you need to enter target server user's password. We can also setup passwordless ssh in Linux between two Linux servers so that you don't have to en