Read command in Linux (read data via keyboard)
The read command in Linux is responsible for receiving data that is entered by users via the keyboard during the execution of a script.
Imagine that you want to know the user’s name to create a directory with their name. See the following script:
Read first name
echo “Hi $first name… I will create a directory with your name”
mkdir $first name When running this script it will ask for your name and create a directory as in the following example:
Uira
Hi Uira… I’ll create a directory with your name See this other example script to find out if a year is a leap year (year with one more day, February 29th, in the Julian calendar).
Fi When running this script, it will ask which year you want to know if it is leap, as in the following example:
Learn much more about Linux in our online course. You can register here. If you already have an account, or want to create one, just log in or create your user here.
Did you like it?
Share