Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to loop over the list of fruits and print each one.
Bash Scripting
for fruit in [1]; do echo "$fruit" done
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the list makes it a single string, not a list.
Using parentheses or brackets is not valid for list iteration in bash.
✗ Incorrect
In bash, to loop over a list of words, you write them separated by spaces without quotes or parentheses.
2fill in blank
mediumComplete the code to loop over the list and print each item in uppercase.
Bash Scripting
for item in apple banana cherry; do [1] "$item" done
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'echo' alone does not change case.
Using 'cut' does not change letter case.
✗ Incorrect
Using 'tr' with input redirection converts the text to uppercase.
3fill in blank
hardFix the error in the loop to correctly iterate over the list and print each element.
Bash Scripting
for i in [1]; do echo "$i" done
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using commas breaks the list into one string.
Using quotes makes the entire list one item.
✗ Incorrect
The list should be space-separated words without quotes or commas for bash to iterate correctly.
4fill in blank
hardFill both blanks to create a loop that prints only fruits with names longer than 5 letters.
Bash Scripting
for fruit in apple banana cherry date; do if [[ ${#fruit} [1] 5 ]]; then echo $[2] fi done
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' would print fruits with names shorter than 5 letters.
Printing 'echo' instead of the variable name.
✗ Incorrect
Use '>' to check if length is greater than 5, and print the fruit variable.
5fill in blank
hardFill all three blanks to create a loop that prints fruits in uppercase only if their name length is less than 7.
Bash Scripting
for fruit in apple banana cherry date; do if [[ ${#fruit} [1] 7 ]]; then [2] "$fruit" | [3] '[:lower:]' '[:upper:]' fi done
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' for the length check.
Using 'cut' or other commands instead of 'tr' for case conversion.
✗ Incorrect
Use '<' to check length less than 7, 'echo' to output the fruit, and 'tr' to convert to uppercase.