0
0
Bash Scriptingscripting~10 mins

String suffix removal (${var%pattern}) in Bash Scripting - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A%'.txt'
B%%'.txt'
C#'.txt'
D##'.txt'
Attempts:
3 left
💡 Hint
Common Mistakes
Using # or ## which remove prefixes instead of suffixes.
Using %% which removes the longest suffix, not the shortest.
2fill in blank
medium

Complete 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'
A%.*
B##.*
C#.*
D%%.*
Attempts:
3 left
💡 Hint
Common Mistakes
Using %% which removes the longest suffix, removing more than intended.
Using # or ## which remove prefixes, not suffixes.
3fill in blank
hard

Fix 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'
A##.backup
B#.backup
C%%.backup
D%.backup
Attempts:
3 left
💡 Hint
Common Mistakes
Using # or ## which remove prefixes instead of suffixes.
Using %% which removes longest suffix unnecessarily.
4fill in blank
hard

Fill 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'
A%'.log'
B%%'.log'
C%%.*
D%.*
Attempts:
3 left
💡 Hint
Common Mistakes
Using %% first removes too much.
Using %.* first removes shortest suffix starting with dot, not '.log'.
5fill in blank
hard

Fill 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'
A${f%.*}
Bf
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using != instead of == in condition.
Using # or ## instead of % for suffix removal.