Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to remove the shortest suffix matching '.txt' from the variable.
Bash Scripting
filename="document.txt" result=${filename[1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using # or ## which remove prefixes instead of suffixes.
Using %% which removes the longest suffix, not the shortest.
✗ Incorrect
The single % removes the shortest matching suffix pattern from the variable's value.
2fill in blank
mediumComplete the code to remove the shortest suffix matching any characters after the last dot.
Bash Scripting
filename="archive.tar.gz" result=${filename[1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using %% which removes the longest suffix, removing more than intended.
Using # or ## which remove prefixes, not suffixes.
✗ Incorrect
Using %.* removes the shortest suffix starting with a dot, effectively removing the file extension.
3fill in blank
hardFix the error in the code to correctly remove the shortest suffix '.backup' from the variable.
Bash Scripting
file="data.backup" clean=${file[1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using # or ## which remove prefixes instead of suffixes.
Using %% which removes longest suffix unnecessarily.
✗ Incorrect
Single % removes the shortest suffix '.backup' correctly; %% removes longest suffix which is unnecessary here.
4fill in blank
hardFill both blanks to remove the shortest suffix '.log' and then the longest suffix starting with a dot.
Bash Scripting
file="server.old.log" step1=${file[1] result=${step1[2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using %% first removes too much.
Using %.* first removes shortest suffix starting with dot, not '.log'.
✗ Incorrect
First remove shortest suffix '.log' with %, then remove longest suffix starting with dot with %%.
5fill in blank
hardFill all three blanks to create a dictionary with keys as filenames without extensions and values as original filenames, filtering only files ending with '.txt'.
Bash Scripting
files=("a.txt" "b.log" "c.txt") result=([1]: [2] for f in files if [[ f [3] *.txt ]])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using != instead of == in condition.
Using # or ## instead of % for suffix removal.
✗ Incorrect
Use ${f%.*} to remove extension for key, f as value, and f == *.txt to filter files ending with '.txt'.