Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to use a here string to pass the word 'hello' to the 'cat' command.
Bash Scripting
cat [1] 'hello'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<<' which is for here documents, not here strings.
Using '<' which reads from a file, not a string.
✗ Incorrect
The here string operator in bash is '<<<'. It passes the string on the right as input to the command on the left.
2fill in blank
mediumComplete the code to count the number of words in the string 'one two three' using a here string.
Bash Scripting
wc -w [1] 'one two three'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' which expects a filename, causing an error.
Using '<<' which expects a delimiter for a here document.
✗ Incorrect
Using '<<<' passes the string as input to 'wc -w' which counts words.
3fill in blank
hardFix the error in the code to correctly use a here string to grep the word 'apple' in the string 'apple banana'.
Bash Scripting
grep apple [1] 'apple banana'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' which expects a file, causing an error.
Using '<<' which is for here documents, not here strings.
✗ Incorrect
The correct operator for passing a string as input is '<<<'.
4fill in blank
hardFill all blanks to create a here string that converts 'hello world' to uppercase using 'tr'.
Bash Scripting
tr [1] [2] [3] 'hello world'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<<' instead of '<<<' for here string.
Swapping the character sets in 'tr'.
✗ Incorrect
The 'tr' command translates characters from the first set to the second. The here string operator '<<<' passes the string as input.
5fill in blank
hardFill both blanks to create a dictionary of word lengths for words longer than 3 letters using a here string and Python.
Bash Scripting
python3 <<< "words = 'apple banana cat dog'.split()\nlengths = [1]: len([2]) for [2] in words if len({{BLANK_2}) > 3}\nprint(lengths)"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'words' instead of 'word' as the loop variable.
Missing closing brace in the dictionary comprehension.
✗ Incorrect
The dictionary comprehension syntax is {word: len(word) for word in words if len(word) > 3}. The here string passes the Python code as input.