Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a function named greet.
Bash Scripting
function [1]() { echo "Hello!" }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function name that does not match the task instruction.
Leaving the function name blank.
✗ Incorrect
The function name should be greet to match the task.
2fill in blank
mediumComplete the code to call the function greet.
Bash Scripting
[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using keywords like 'call' or 'run' which are not valid in bash.
Adding parentheses when calling the function.
✗ Incorrect
In bash, to call a function, just write its name.
3fill in blank
hardFix the error in the function definition to make it valid bash syntax.
Bash Scripting
function greet [1] echo "Hello!" }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses or brackets instead of curly braces.
Missing the opening brace.
✗ Incorrect
The function body must start with a curly brace { in bash.
4fill in blank
hardFill both blanks to create a function that prints a passed name.
Bash Scripting
function [1]() { [2]="$1" echo "Hello, $[2]!" }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that is not passed or defined.
Using a function name that does not match the task.
✗ Incorrect
The function name is say_hello and the variable holding the name is name.
5fill in blank
hardComplete the code to call the function say_hello with the argument 'Alice'.
Bash Scripting
say_hello "[1]"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Adding 'bash' or './' before the function name when calling inside a script.
Putting quotes around the function name.
✗ Incorrect
To call a function in bash script, just write its name followed by arguments separated by spaces. No extra keywords needed.