0
0
Bash Scriptingscripting~10 mins

Adding and removing 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 add an element to the end of a bash array.

Bash Scripting
my_array=(apple banana cherry)
my_array+=([1])
Drag options to blanks, or click blank then click option'
A"egg"
B"fig"
C"date"
D"grape"
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to quote the element.
Using '=' instead of '+=' which replaces the array.
2fill in blank
medium

Complete the code to remove the second element from a bash array.

Bash Scripting
my_array=(apple banana cherry date)
unset my_array[[1]]
Drag options to blanks, or click blank then click option'
A1
B3
C0
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using 2 instead of 1 for the second element index.
Trying to remove element by value instead of index.
3fill in blank
hard

Fix the error in the code to correctly add an element to the array.

Bash Scripting
my_array=(apple banana cherry)
my_array=[1] "date"
Drag options to blanks, or click blank then click option'
Aappend
B=
C+=
Dadd
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' which replaces the entire array.
Using non-existent commands like 'append' or 'add'.
4fill in blank
hard

Fill both blanks to create an array and then remove the last element.

Bash Scripting
my_array=([1])
unset my_array[[2]]
Drag options to blanks, or click blank then click option'
A"apple" "banana" "cherry"
B2
C3
D"date" "fig"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong indexes to remove elements.
Incorrectly formatting the array elements.
5fill in blank
hard

Fill all three blanks to add two elements and then remove the first element from the array.

Bash Scripting
my_array=(apple)
my_array+=([1])
my_array+=([2])
unset my_array[[3]]
Drag options to blanks, or click blank then click option'
A"banana"
B"cherry"
C0
D"date"
Attempts:
3 left
💡 Hint
Common Mistakes
Removing the wrong index.
Trying to add multiple elements in one '+=' without quotes.