0
0
Bash Scriptingscripting~10 mins

Function definition 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 define a function named greet.

Bash Scripting
function [1]() {
  echo "Hello!"
}
Drag options to blanks, or click blank then click option'
Agreet
Bhello
Csay_hello
Dwelcome
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different function name than asked.
Forgetting the parentheses after the function name.
2fill in blank
medium

Complete the code to call the function named greet.

Bash Scripting
[1]
Drag options to blanks, or click blank then click option'
Afunction greet
Bcall greet
Crun greet
Dgreet()
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.
3fill in blank
hard

Fix 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'
A{}
B()
C[]
D<>
Attempts:
3 left
💡 Hint
Common Mistakes
Using curly braces or square brackets instead of parentheses.
Omitting parentheses entirely.
4fill in blank
hard

Fill 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'
Asay_hello
Bgreet
Chello
Dwelcome
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for definition and call.
Forgetting parentheses when calling the function.
5fill in blank
hard

Fill 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'
Agreet_user
B1
Dname
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.