Bird
0
0

Find the error in this script that tries to add "blue" to array colors:

medium📝 Debug Q7 of 15
Bash Scripting - Arrays
Find the error in this script that tries to add "blue" to array colors:
colors=("red" "green")
colors=colors+"blue"
echo "${colors[@]}"
AMissing parentheses when adding element
BMissing quotes around "blue"
CUsing wrong array name
DEcho syntax is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Check how element is added

    Adding element requires parentheses: colors+=("blue").
  2. Step 2: Identify error

    Using colors=colors+"blue" treats it as string concatenation, not array append.
  3. Final Answer:

    Missing parentheses when adding element -> Option A
  4. Quick Check:

    Use += with parentheses to add array element [OK]
Quick Trick: Always use parentheses with += to add array elements [OK]
Common Mistakes:
MISTAKES
  • Forgetting parentheses causes string concat
  • Not quoting new element
  • Confusing string and array operations

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes