0
0
Bash Scriptingscripting~15 mins

read command in Bash Scripting - Mini Project: Build & Apply

Choose your learning style9 modes available
Using the read Command in Bash
📖 Scenario: You want to create a simple script that asks a user for their name and age, then uses that information to display a greeting message.
🎯 Goal: Build a Bash script that uses the read command to get user input and then prints a message using that input.
📋 What You'll Learn
Use the read command to get user input
Store the input in variables named name and age
Print a greeting message using the input values
💡 Why This Matters
🌍 Real World
Scripts often need to ask users for information like names, passwords, or choices. The <code>read</code> command is the basic way to get this input in Bash.
💼 Career
Knowing how to get user input in scripts is essential for system administrators, DevOps engineers, and anyone automating tasks with Bash.
Progress0 / 4 steps
1
Create variables to hold user input
Write a Bash script that uses the read command to get the user's name and store it in a variable called name.
Bash Scripting
Need a hint?

Use read -p "Enter your name: " name to prompt and store input.

2
Add input for user's age
Add a read command to get the user's age and store it in a variable called age.
Bash Scripting
Need a hint?

Use read -p "Enter your age: " age to prompt and store input.

3
Create a greeting message using the input
Write a echo command that prints: Hello, [name]! You are [age] years old. using the variables name and age.
Bash Scripting
Need a hint?

Use echo "Hello, $name! You are $age years old." to print the message.

4
Run the script and display the output
Run the script and show the output after entering John as the name and 30 as the age. The output should be: Hello, John! You are 30 years old.
Bash Scripting
Need a hint?

Type John when prompted for name and 30 when prompted for age.