0
0
Bash Scriptingscripting~10 mins

Accessing array elements 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 print the first element of the array.

Bash Scripting
arr=(apple banana cherry)
echo ${arr[[1]]}
Drag options to blanks, or click blank then click option'
A0
B1
C3
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 1 to get the first element.
Forgetting the square brackets.
Using parentheses instead of brackets.
2fill in blank
medium

Complete the code to print the last element of the array.

Bash Scripting
arr=(dog cat mouse)
echo ${arr[[1]]}
Drag options to blanks, or click blank then click option'
A1
B2
C3
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using a negative index.
Using index 3 which is out of range.
Using index 1 which is the second element.
3fill in blank
hard

Fix the error in the code to print the second element of the array.

Bash Scripting
arr=(red green blue)
echo ${arr[[1]]}
Drag options to blanks, or click blank then click option'
A1
B{1}
C(1)
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses or curly braces instead of square brackets.
Using index 2 which is the third element.
Forgetting the dollar sign before the array.
4fill in blank
hard

Fill the three blanks to print the third element of the array.

Bash Scripting
arr=(sun moon stars)
echo ${arr[{BLANK_2}}]
Drag options to blanks, or click blank then click option'
A[
B]
C2
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong brackets or missing one bracket.
Using index 3 which is out of range.
Putting brackets in the wrong order.
5fill in blank
hard

Complete the code to print the second element of the array.

Bash Scripting
arr=(one two three)
echo ${arr[{BLANK_2}}]
Drag options to blanks, or click blank then click option'
A[
B1
C]
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 2 which is the third element.
Missing one of the brackets.
Putting brackets after the index.