Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to convert all lowercase letters in the input to uppercase using tr.
Bash Scripting
echo "hello world" | tr [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to quote the character sets.
Swapping the order of character sets.
✗ Incorrect
The
tr command uses the syntax tr 'a-z' 'A-Z' to convert lowercase letters to uppercase.2fill in blank
mediumComplete the code to replace all spaces with underscores using tr.
Bash Scripting
echo "hello world" | tr [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the space character.
Using the wrong order of characters.
✗ Incorrect
The
tr command replaces characters from the first set with those in the second set. Here, spaces are replaced with underscores.3fill in blank
hardFix the error in the code to delete all digits from the input using tr.
Bash Scripting
echo "abc123def" | tr -d [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect character ranges like
1-9 which misses zero.Trying to delete letters instead of digits.
✗ Incorrect
The
-d option deletes characters. To delete digits, use the range 0-9.4fill in blank
hardFill both blanks to replace all vowels with the letter 'x' using tr.
Bash Scripting
echo "hello world" | tr [1] [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not including uppercase vowels.
Using multiple characters in the replacement set.
✗ Incorrect
To replace vowels (both lowercase and uppercase) with 'x', use
tr 'aeiouAEIOU' 'x'.5fill in blank
hardFill all three blanks to create a dictionary that maps each word to its length, but only for words longer than 3 characters.
Bash Scripting
words=("apple" "bat" "cat" "dog" "elephant") for word in "${words[@]}"; do if [[ ${#word} [1] [2] ]]; then echo "${word}: $[3]" fi done
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using less than instead of greater than.
Printing the word instead of its length.
✗ Incorrect
The code checks if the length of the word is greater than 3, then prints the word and its length.