Bird
0
0

How can you modify this script to accept a user's name as input and greet them?

hard🚀 Application Q9 of 15
Bash Scripting - Basics
How can you modify this script to accept a user's name as input and greet them?
#!/bin/bash
echo "Enter your name:"
echo "Hello, $name!"
AReplace <code>echo</code> with <code>print</code>
BAdd <code>read name</code> after the prompt to get input
CUse single quotes around $name in echo
DRemove the read command
Step-by-Step Solution
Solution:
  1. Step 1: Understand input reading

    The read command waits for user input and stores it in a variable.
  2. Step 2: Check script correctness

    Adding read name after prompt captures input; echo then greets user.
  3. Final Answer:

    Add read name after the prompt to get input -> Option B
  4. Quick Check:

    Use read to get user input [OK]
Quick Trick: Use read to capture user input in Bash [OK]
Common Mistakes:
MISTAKES
  • Using print instead of echo
  • Using single quotes preventing variable expansion
  • Removing read command loses input

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes