Recall & Review
beginner
What is an indexed array in Bash scripting?
An indexed array in Bash is a list of values stored in a single variable, where each value has a numeric index starting from 0.
Click to reveal answer
beginner
How do you declare an indexed array with values in Bash?
Use syntax:
array_name=(value1 value2 value3). For example: fruits=(apple banana cherry).Click to reveal answer
beginner
How do you access the second element of an indexed array named
colors?Use
${colors[1]} because indexing starts at 0.Click to reveal answer
intermediate
How to add a new element to an existing indexed array in Bash?
Use syntax:
array_name+=(new_value). For example: fruits+=('orange') adds 'orange' to the fruits array.Click to reveal answer
beginner
What command shows all elements of an indexed array named
my_array?Use
echo ${my_array[@]} to print all elements separated by spaces.Click to reveal answer
How do you declare an indexed array named
pets with elements 'dog', 'cat', and 'bird'?✗ Incorrect
In Bash, indexed arrays are declared with parentheses and space-separated values.
What is the index of the first element in a Bash indexed array?
✗ Incorrect
Bash arrays start indexing at 0, like many programming languages.
How do you print all elements of an indexed array
colors?✗ Incorrect
Both ${colors[@]} and ${colors[*]} print all elements, but ${colors[@]} is preferred for separate elements.
How to add 'pear' to an existing array
fruits?✗ Incorrect
In Bash, use += with parentheses to add elements to an array.
Which syntax is correct to access the third element of array
numbers?✗ Incorrect
Indexing starts at 0, so the third element is at index 2.
Explain how to declare and access elements in an indexed array in Bash.
Think about how you list items in a shopping list and then pick one by its position.
You got /4 concepts.
Describe how to add a new element to an existing indexed array in Bash.
Imagine adding a new item to your list without rewriting the whole list.
You got /4 concepts.