0
0
Bash Scriptingscripting~10 mins

tr for character transformation 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 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'
A"a-z A-Z"
B"a-z" "A-Z"
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to quote the character sets.
Swapping the order of character sets.
2fill in blank
medium

Complete 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'
A" _"
C" " "_"
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the space character.
Using the wrong order of characters.
3fill in blank
hard

Fix 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'
A"0-9"
B"a-z"
C"A-Z"
D"1-9"
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect character ranges like 1-9 which misses zero.
Trying to delete letters instead of digits.
4fill in blank
hard

Fill 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'
A"aeiou"
B"xyz"
C"x"
D"aeiouAEIOU"
Attempts:
3 left
💡 Hint
Common Mistakes
Not including uppercase vowels.
Using multiple characters in the replacement set.
5fill in blank
hard

Fill 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'
A>
B3
C${#word}
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using less than instead of greater than.
Printing the word instead of its length.