Bird
0
0

What is the main purpose of using declare -A in a Bash script?

easy🧠 Conceptual Q11 of 15
Bash Scripting - Arrays
What is the main purpose of using declare -A in a Bash script?
ATo define a function
BTo declare a regular indexed array
CTo create an associative array with named keys
DTo start a loop
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role of declare -A

    This command is used in Bash to declare an associative array, which means the array uses named keys instead of numbers.
  2. Step 2: Differentiate from other declarations

    Regular arrays use numbers as keys and are declared without -A. Functions and loops are declared differently.
  3. Final Answer:

    To create an associative array with named keys -> Option C
  4. Quick Check:

    declare -A means associative array [OK]
Quick Trick: Remember: -A means associative array with named keys [OK]
Common Mistakes:
MISTAKES
  • Confusing associative arrays with regular indexed arrays
  • Thinking declare -A creates a function
  • Assuming declare -A starts a loop

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes