0
0
Bash Scriptingscripting~20 mins

Indexed array declaration in Bash Scripting - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Indexed Array Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of Indexed Array Declaration and Access
What is the output of this Bash script?
Bash Scripting
arr=(apple banana cherry)
echo ${arr[1]}
A1
Bapple
Ccherry
Dbanana
Attempts:
2 left
💡 Hint
Remember that Bash arrays start indexing at 0.
💻 Command Output
intermediate
2:00remaining
Length of Indexed Array
What does this Bash command output?
Bash Scripting
arr=(one two three four)
echo ${#arr[@]}
A4
B3
Cone two three four
D0
Attempts:
2 left
💡 Hint
${#arr[@]} gives the number of elements in the array.
📝 Syntax
advanced
2:00remaining
Identify the Correct Indexed Array Declaration
Which option correctly declares an indexed array with elements 'red', 'green', 'blue' in Bash?
Aarr={red, green, blue}
Barr=(red green blue)
Carr=[red, green, blue]
Darr='red green blue'
Attempts:
2 left
💡 Hint
Bash arrays use parentheses without commas.
💻 Command Output
advanced
2:00remaining
Output of Array Element Assignment
What is the output of this Bash script?
Bash Scripting
arr=()
arr[2]=orange
arr[0]=lemon
echo ${arr[@]}
Alemon
Borange lemon
Clemon orange
Dorange
Attempts:
2 left
💡 Hint
Elements can be assigned at specific indexes; missing indexes are empty.
💻 Command Output
expert
2:00remaining
Output of Indexed Array with Mixed Assignments
What is the output of this Bash script?
Bash Scripting
arr=(a b c)
arr[5]=f
echo ${#arr[@]}
A4
B6
C3
D5
Attempts:
2 left
💡 Hint
The length counts the number of assigned elements, not the highest index.