Bird
0
0

You want to write a script that works in both Bash and Zsh but uses arrays. Which syntax should you use?

hard🚀 Application Q8 of 15
Bash Scripting - Basics
You want to write a script that works in both Bash and Zsh but uses arrays. Which syntax should you use?
Adeclare -a array=(one two three)
Bset -A array one two three
Carray=(one two three)
Darray=one two three
Step-by-Step Solution
Solution:
  1. Step 1: Identify array syntax compatible with Bash and Zsh

    Both Bash and Zsh support array=(one two three) syntax.
  2. Step 2: Evaluate other options

    set -A is for ksh, declare -a is Bash-specific, and array=one two three is invalid.
  3. Final Answer:

    array=(one two three) -> Option C
  4. Quick Check:

    Compatible array syntax Bash & Zsh = array=(...) [OK]
Quick Trick: Use array=(...) for Bash and Zsh arrays [OK]
Common Mistakes:
MISTAKES
  • Using declare -a which is Bash-only
  • Using set -A which is ksh syntax
  • Assigning array without parentheses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes