Recall & Review
beginner
How do you add an element to an array in Bash?
Use the syntax:
array+=("new_element"). This appends new_element to the end of the array.Click to reveal answer
beginner
How can you remove an element from a Bash array by index?
Use
unset array[index] to remove the element at the specified index from the array.Click to reveal answer
intermediate
What happens if you unset an array element in Bash?
The element at that index is removed, but the array keeps its other elements and indexes. The array length decreases by one.
Click to reveal answer
intermediate
How do you add multiple elements to a Bash array at once?
Use
array+=("elem1" "elem2" "elem3") to add several elements in one command.Click to reveal answer
advanced
Can you remove an element from a Bash array by value directly?
No, Bash does not have a direct way to remove by value. You need to loop through the array and rebuild it without the unwanted value.
Click to reveal answer
Which command adds an element 'apple' to a Bash array named fruits?
✗ Incorrect
The correct syntax to add an element to a Bash array is
array+=("element").How do you remove the element at index 2 from a Bash array named items?
✗ Incorrect
Use
unset items[2] to remove the element at index 2.What happens to the array indexes after unsetting an element in Bash?
✗ Incorrect
Unsetting an element removes it but does not shift other elements; indexes remain as they were.
Which of these is a correct way to add multiple elements to a Bash array named colors?
✗ Incorrect
You can add multiple elements by listing them inside parentheses with +=.
Is there a direct Bash command to remove an element by its value from an array?
✗ Incorrect
Bash does not support removing by value directly; you must manually filter the array.
Explain how to add and remove elements in a Bash array with examples.
Think about how you add one or many elements and how you remove by index.
You got /4 concepts.
Describe why Bash does not allow removing array elements by value directly and how you can work around it.
Consider how you would filter a list manually.
You got /4 concepts.