0
0
Bash Scriptingscripting~15 mins

Why input makes scripts interactive in Bash Scripting - See It in Action

Choose your learning style9 modes available
Why input makes scripts interactive
📖 Scenario: Imagine you want to create a simple script that asks a user for their name and then greets them. This shows how scripts can interact with people by asking questions and using their answers.
🎯 Goal: Build a bash script that asks for the user's name, stores it, and then prints a greeting using that name.
📋 What You'll Learn
Use the read command to get user input
Store the input in a variable called name
Print a greeting message using the echo command and the name variable
💡 Why This Matters
🌍 Real World
Many scripts ask users for information like names, passwords, or choices to work correctly.
💼 Career
Understanding how to get user input is key for writing interactive scripts used in automation, system setup, and user tools.
Progress0 / 4 steps
1
Create a variable to hold the user's name
Create a variable called name and set it to an empty string.
Bash Scripting
Need a hint?

Use name="" to create an empty variable.

2
Ask the user to enter their name
Use the read command with the variable name to get input from the user with the prompt "Enter your name:".
Bash Scripting
Need a hint?

Use echo to show the prompt, then read name to get input.

3
Create a greeting message using the input
Use the echo command to print the message "Hello, " followed by the value of the variable name.
Bash Scripting
Need a hint?

Use echo "Hello, $name" to greet the user.

4
Run the script to see the interactive greeting
Run the script and enter the name Alex when prompted. The script should print Hello, Alex.
Bash Scripting
Need a hint?

Type Alex when the script asks for your name.