Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to remove the shortest prefix 'abc' from the variable.
Bash Scripting
result=${var[1]abc} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using ## removes the longest prefix instead of the shortest.
Using % or %% removes suffixes, not prefixes.
✗ Incorrect
The single # removes the shortest matching prefix pattern from the variable.
2fill in blank
mediumComplete the code to remove the shortest prefix matching any characters up to 'end'.
Bash Scripting
result=${var[1]*end} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using ## removes the longest prefix, which may remove more than intended.
Using % or %% removes suffixes, not prefixes.
✗ Incorrect
Using # with '*end' removes the shortest prefix ending with 'end'.
3fill in blank
hardFix the error in the code to remove the shortest prefix 'temp_' from the variable.
Bash Scripting
cleaned=${var[1]temp_} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using % or %% tries to remove suffixes, causing no change.
Using ## removes the longest prefix, which may remove more than intended.
✗ Incorrect
The single # removes the shortest prefix 'temp_' from the variable.
4fill in blank
hardFill both blanks to remove the shortest prefix matching 'log_' and assign to output.
Bash Scripting
output=$[1][2]log_}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using ## removes the longest prefix, which is not correct here.
Using wrong variable names like 'file' causes errors.
✗ Incorrect
Use 'var' as the variable name and '#' to remove the shortest prefix 'log_'.
5fill in blank
hardFill all three blanks to create a dictionary with keys as filenames without 'tmp_' prefix and values as their sizes.
Bash Scripting
declare -A sizes; for [3] in tmp_files; do sizes[[1]]=$(stat -c%s [2]); done
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using ${file##tmp_} removes the longest prefix, which may remove more than intended.
Using different variable names inconsistently causes errors.
✗ Incorrect
Use '${file#tmp_}' to remove the shortest 'tmp_' prefix for keys, '$file' as the filename for stat, and 'file' as the loop variable.