Bird
0
0

What will be the output of this script if name="John Doe" and the command is echo Hello $name without quotes?

medium📝 Command Output Q13 of 15
Bash Scripting - Quoting and Expansion
What will be the output of this script if name="John Doe" and the command is echo Hello $name without quotes?
AHello John Doe
BHello John
CHello John Doe (with quotes)
DSyntax error
Step-by-Step Solution
Solution:
  1. Step 1: Analyze how bash splits unquoted variables

    Without quotes, $name expands to two words: 'John' and 'Doe'. The echo command treats them as separate arguments.
  2. Step 2: Understand echo behavior with multiple arguments

    Echo prints all arguments separated by spaces, so it prints 'Hello John Doe'. The command echo Hello $name without quotes prints three words separated by spaces.
  3. Final Answer:

    Hello John Doe -> Option A
  4. Quick Check:

    Unquoted variable splits words = C [OK]
Quick Trick: Unquoted variables split on spaces, producing multiple words [OK]
Common Mistakes:
MISTAKES
  • Thinking output is one word
  • Confusing quotes effect
  • Expecting syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes