0
0
Bash Scriptingscripting~10 mins

Why functions organize reusable code in Bash Scripting - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a function named greet.

Bash Scripting
function [1]() {
  echo "Hello!"
}
Drag options to blanks, or click blank then click option'
Ahello
Bgreet
CsayHello
Dprint
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function name that does not match the task instruction.
Leaving the function name blank.
2fill in blank
medium

Complete the code to call the function greet.

Bash Scripting
[1]
Drag options to blanks, or click blank then click option'
Arun greet
Bcall greet
Cgreet
Dexecute greet
Attempts:
3 left
💡 Hint
Common Mistakes
Using keywords like 'call' or 'run' which are not valid in bash.
Adding parentheses when calling the function.
3fill in blank
hard

Fix 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'
A{
B<
C[
D(
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses or brackets instead of curly braces.
Missing the opening brace.
4fill in blank
hard

Fill 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'
Asay_hello
Bname
Cuser
Dgreet
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.
5fill in blank
hard

Complete 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'
Abash
CAlice
D./
Attempts:
3 left
💡 Hint
Common Mistakes
Adding 'bash' or './' before the function name when calling inside a script.
Putting quotes around the function name.