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 different function name than asked.
Forgetting the parentheses after the function name.
✗ Incorrect
The function name should be greet to match the task.
2fill in blank
mediumComplete the code to call the function named greet.
Bash Scripting
[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Writing 'call greet' which is not valid bash syntax.
Writing 'function greet' which defines a function, not calls it.
✗ Incorrect
To call a function in bash, write its name followed by parentheses: greet().
3fill in blank
hardFix the error in the function definition to make it valid bash syntax.
Bash Scripting
function greet [1] { echo "Hi!" }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using curly braces or square brackets instead of parentheses.
Omitting parentheses entirely.
✗ Incorrect
In bash, function parameters are declared with parentheses () after the function name.
4fill in blank
hardFill both blanks to define and call a function named say_hello.
Bash Scripting
function [1]() { echo "Hello, world!" } [2]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for definition and call.
Forgetting parentheses when calling the function.
✗ Incorrect
The function name must be the same in definition and call: say_hello.
5fill in blank
hardFill all three blanks to define a function greet_user that takes a name and prints a greeting.
Bash Scripting
function [1]() { echo "Hello, $[2]!" } [3] "Alice"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable name instead of argument position.
Calling the function with a different name.
Forgetting to use $ before the argument number.
✗ Incorrect
The function name is greet_user. The first argument is accessed as $1. Call the function with greet_user "Alice".