Bird
0
0

Which of the following is a valid way to assign a value to an associative array element in Bash?

easy🧠 Conceptual Q2 of 15
Bash Scripting - Arrays
Which of the following is a valid way to assign a value to an associative array element in Bash?
Aarr[key]:value
Barr[key]=value
Carr(key)=value
Darr->key=value
Step-by-Step Solution
Solution:
  1. Step 1: Recall associative array syntax

    In Bash, associative array elements are assigned using square brackets with the key inside.
  2. Step 2: Check each option

    Only arr[key]=value uses correct syntax; others use invalid symbols.
  3. Final Answer:

    arr[key]=value -> Option B
  4. Quick Check:

    Assign associative array element = arr[key]=value [OK]
Quick Trick: Use square brackets for keys in associative arrays [OK]
Common Mistakes:
MISTAKES
  • Using parentheses instead of brackets
  • Using colon or arrow syntax
  • Missing the equal sign

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes