Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to extract the substring 'world' from the variable.
Bash Scripting
text="hello world" sub=${text:[1]:5} echo "$sub"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using offset 0 or 1 extracts the wrong part of the string.
Forgetting that offset counts from zero.
✗ Incorrect
The substring extraction syntax ${var:offset:length} starts at offset 6 to get 'world' from 'hello world'.
2fill in blank
mediumComplete the code to extract the first 4 characters from the variable.
Bash Scripting
filename="report2024.txt" prefix=${filename:[1]:4} echo "$prefix"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Starting at offset 1 misses the first character.
Using offset equal to length extracts nothing.
✗ Incorrect
Offset 0 starts at the beginning, so ${filename:0:4} extracts 'repo'.
3fill in blank
hardFix the error in the code to correctly extract '2024' from the filename.
Bash Scripting
filename="report2024.txt" year=${filename:[1]:4} echo "$year"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using offset 7 or 4 extracts wrong parts.
Confusing offset with length.
✗ Incorrect
The year '2024' starts at offset 6 in 'report2024.txt', so ${filename:6:4} extracts it correctly.
4fill in blank
hardFill both blanks to extract 'script' from the variable.
Bash Scripting
word="bashscript" sub=${word:[1]:[2] echo "$sub"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong offset or length extracts incorrect substring.
Mixing up offset and length values.
✗ Incorrect
The substring 'script' starts at offset 4 and has length 6 in 'bashscript'.
5fill in blank
hardFill both blanks to extract 'log' from the filename variable.
Bash Scripting
filename="system.log.2024" sub=${filename:[1]:[2] echo "$sub"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using offset 6 or 4 extracts wrong substring.
Using length 4 extracts extra characters.
✗ Incorrect
The substring 'log' starts at offset 7 and has length 3 in 'system.log.2024'.