Challenge - 5 Problems
Prefix Removal Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate1:30remaining
What is the output of this prefix removal?
Given the variable
file="backup_2024_report.txt", what is the output of echo ${file#backup_}?Bash Scripting
file="backup_2024_report.txt" echo ${file#backup_}
Attempts:
2 left
💡 Hint
The # operator removes the shortest match of the pattern from the start of the string.
✗ Incorrect
The pattern 'backup_' matches the prefix 'backup_' exactly, so it is removed, leaving '2024_report.txt'.
💻 Command Output
intermediate1:30remaining
Removing shortest vs longest prefix
Given
path="/home/user/docs/file.txt", what is the output of echo ${path##*/}?Bash Scripting
path="/home/user/docs/file.txt" echo ${path##*/}
Attempts:
2 left
💡 Hint
The ## operator removes the longest match of the pattern from the start.
✗ Incorrect
The pattern '*/' matches everything up to the last slash, so it removes '/home/user/docs/' leaving 'file.txt'.
🔧 Debug
advanced2:00remaining
Why does this prefix removal fail?
Consider
var="version1.2.3". What error or output results from echo ${var#version.}?Bash Scripting
var="version1.2.3" echo ${var#version.}
Attempts:
2 left
💡 Hint
The pattern must match exactly at the start to be removed.
✗ Incorrect
The pattern 'version.' does not match the start because the string has 'version1' without a dot after 'version'. So no removal happens.
🧠 Conceptual
advanced1:30remaining
What does this prefix removal pattern do?
Given
text="error_404_not_found", what is the output of echo ${text#*_}?Bash Scripting
text="error_404_not_found" echo ${text#*_}
Attempts:
2 left
💡 Hint
The pattern '*_' removes the shortest prefix ending with underscore.
✗ Incorrect
The pattern '*_' matches everything up to the first underscore, so it removes 'error_' leaving '404_not_found'.
🚀 Application
expert2:30remaining
Extract filename without extension using prefix removal
Given
filename="archive.tar.gz", which command outputs tar.gz by removing the shortest prefix ending with a dot?Bash Scripting
filename="archive.tar.gz"
echo ???Attempts:
2 left
💡 Hint
Use # to remove shortest prefix matching pattern including a dot.
✗ Incorrect
The pattern '*.' removes everything up to the first dot, so ${filename#*.} removes 'archive.' leaving 'tar.gz'.