0
0
Bash Scriptingscripting~10 mins

Indexed array declaration in Bash Scripting - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A(apple banana cherry)
B[0]=apple [1]=banana [2]=cherry
C"apple" "banana" "cherry"
Dapple, banana, cherry
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.
2fill in blank
medium

Complete 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'
A[2]
B[0]
C[1]
D[3]
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 2 instead of 1 for the second element.
Forgetting the square brackets around the index.
3fill in blank
hard

Fix 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'
A(1 2 3 4 5)
B[1 2 3 4 5]
C{1,2,3,4,5}
D"1 2 3 4 5"
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.
4fill in blank
hard

Fill 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'
A(dog cat bird)
B[0]
C[1]
D"dog cat bird"
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes instead of parentheses for declaration.
Using index 1 instead of 0 to access the first element.
5fill in blank
hard

Fill 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'
A(hammer screwdriver)
B2
C"wrench"
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong indices when adding or printing elements.
Not using quotes around the new element string.