Bird
0
0

What will be the output of this Bash script?

medium📝 Command Output Q4 of 15
Bash Scripting - Arrays
What will be the output of this Bash script?
declare -A capitals
capitals[France]=Paris
capitals[Japan]=Tokyo
echo ${capitals[Japan]}
AParis
BTokyo
Ccapitals[Japan]
DError: invalid syntax
Step-by-Step Solution
Solution:
  1. Step 1: Understand the associative array assignments

    The script assigns "Paris" to key "France" and "Tokyo" to key "Japan".
  2. Step 2: Check the echo command

    The echo prints the value for key "Japan", which is "Tokyo".
  3. Final Answer:

    Tokyo -> Option B
  4. Quick Check:

    Access associative array by key = Tokyo [OK]
Quick Trick: Use ${array[key]} to get associative array value [OK]
Common Mistakes:
MISTAKES
  • Printing the key instead of value
  • Syntax errors in echo
  • Confusing keys and values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes