Bird
0
0

Given the script:

hard🚀 Application Q9 of 15
Bash Scripting - Variables
Given the script:
var1="Hello"
var2="World"
combined="$var1 $var2"
echo $combined

What is the output and why?
A$var1 $var2 - Variables not expanded
BHelloWorld - Variables concatenated without space
CHello World - Variables concatenated with space
DHello $var2 - Only first variable expanded
Step-by-Step Solution
Solution:
  1. Step 1: Analyze variable concatenation

    Variables var1 and var2 are combined with a space between them inside double quotes.
  2. Step 2: Understand variable expansion

    Double quotes allow variable expansion, so $var1 $var2 becomes "Hello World".
  3. Final Answer:

    Hello World - Variables concatenated with space -> Option C
  4. Quick Check:

    Double quotes expand variables and preserve spaces [OK]
Quick Trick: Use double quotes to concatenate variables with spaces [OK]
Common Mistakes:
MISTAKES
  • Forgetting space between variables
  • Using single quotes preventing expansion
  • Not quoting combined string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes