Bird
0
0

Which of the following is the correct syntax to read a variable user with a default value 'admin' if input is empty?

easy📝 Syntax Q12 of 15
Bash Scripting - User Input
Which of the following is the correct syntax to read a variable user with a default value 'admin' if input is empty?
Aread user; user=${user:-admin}
Bread user || user=admin
Cread user && user=admin
Dread user ? user=admin
Step-by-Step Solution
Solution:
  1. Step 1: Understand how to read input and set default

    The read command takes input into user. To set a default if empty, use user=${user:-admin}.
  2. Step 2: Check each option

    read user; user=${user:-admin} correctly reads input then sets default if empty. Options A, C, D use invalid syntax for default assignment.
  3. Final Answer:

    read user; user=${user:-admin} -> Option A
  4. Quick Check:

    Correct default syntax after read = read user; user=${user:-admin} [OK]
Quick Trick: Use read then assign default with ${var:-default} [OK]
Common Mistakes:
MISTAKES
  • Using || or && incorrectly for default assignment
  • Trying to assign default inside read command
  • Using invalid operators like ? for default

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes