>_ IzzyLab

Topic breakdown

An array in bash is a variable that holds an ordered list of values; it's declared with parentheses, an individual element is accessed by index starting from zero, and all of them at once via the special index [@]. To iterate over all elements you use a for ... in loop that goes over the array's expansion. The key point is the quotes around "${arr[@]}": they keep each element as a separate word even with spaces inside; without them the list would "drift" due to word splitting. The script's finished output is placed into a file with the redirection operator >.

What's checked

  1. 3 lines in the output
  2. array elements are present in the output
  3. fruits.sh declares an array

What it looks like