Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare an indexed array named 'fruits' with three elements.
Bash Scripting
fruits=[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using commas between elements instead of spaces.
Using quotes around the whole list instead of individual elements.
Using key=value pairs which is for associative arrays.
✗ Incorrect
In bash, indexed arrays are declared using parentheses with space-separated values, like (apple banana cherry).
2fill in blank
mediumComplete the code to print the second element of the 'colors' array.
Bash Scripting
echo ${colors[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 2 instead of 1 for the second element.
Forgetting the square brackets around the index.
✗ Incorrect
Array indices in bash start at 0, so the second element is at index 1.
3fill in blank
hardFix the error in the array declaration to correctly declare an indexed array named 'numbers'.
Bash Scripting
numbers=[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets which is invalid for array declaration.
Using curly braces or quotes which create strings, not arrays.
✗ Incorrect
Indexed arrays in bash are declared with parentheses and space-separated values.
4fill in blank
hardFill both blanks to declare an indexed array 'pets' with three elements and print the first element.
Bash Scripting
pets=[1] echo ${pets[2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes instead of parentheses for declaration.
Using index 1 instead of 0 to access the first element.
✗ Incorrect
The array is declared with parentheses and elements separated by spaces. The first element is at index 0.
5fill in blank
hardFill all three blanks to declare an indexed array 'tools', add a new element, and print the last element.
Bash Scripting
tools=[1] tools[[2]]=[3] echo ${tools[2]}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong indices when adding or printing elements.
Not using quotes around the new element string.
✗ Incorrect
Declare the array with two elements, add a third at index 2, then print the element at index 2.