Bird
0
0

What is the correct syntax to add the element "dog" to the end of a Bash array named pets?

easy📝 Syntax Q3 of 15
Bash Scripting - Arrays
What is the correct syntax to add the element "dog" to the end of a Bash array named pets?
Apets=(dog)
Bpets+=("dog")
Cpets=(pets "dog")
Dpets=+"dog"
Step-by-Step Solution
Solution:
  1. Step 1: Use += operator with parentheses

    To add an element, use array+=("element") syntax.
  2. Step 2: Add "dog" correctly

    So, pets+=("dog") appends "dog" to the array.
  3. Final Answer:

    pets+=("dog") -> Option B
  4. Quick Check:

    Append element syntax = B [OK]
Quick Trick: Use += with parentheses and quotes to add element [OK]
Common Mistakes:
MISTAKES
  • Missing parentheses causes syntax error
  • Not quoting string can cause word splitting
  • Using invalid operators like =+

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes