0
0
Bash Scriptingscripting~10 mins

Calling functions 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 call the function named greet.

Bash Scripting
greet() {
  echo "Hello!"
}

[1]
Drag options to blanks, or click blank then click option'
Agreet()
Bcall greet
Crun greet
Dgreet
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses when calling the function causes errors.
Trying to use 'call' or 'run' commands which don't exist in bash.
2fill in blank
medium

Complete the code to call the function say_hello with an argument.

Bash Scripting
say_hello() {
  echo "Hello, $1!"
}

[1]
Drag options to blanks, or click blank then click option'
Asay_hello(John)
Bsay_hello John
Csay_hello
Dcall say_hello John
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses around arguments like in other languages.
Trying to use 'call' keyword which is not valid in bash.
3fill in blank
hard

Fix the error in calling the function print_date correctly.

Bash Scripting
print_date() {
  date
}

[1]
Drag options to blanks, or click blank then click option'
Aprint_date {}
Bprint_date()
Cprint_date
Dcall print_date
Attempts:
3 left
💡 Hint
Common Mistakes
Adding parentheses when calling the function.
Using 'call' keyword which is invalid in bash.
4fill in blank
hard

Fill both blanks to call the function greet_user with the argument 'Alice'.

Bash Scripting
greet_user() {
  echo "Welcome, $1!"
}

[1] [2]
Drag options to blanks, or click blank then click option'
Agreet_user
BAlice
C'Alice'
Dgreet_user()
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses when calling the function.
Adding quotes around the argument which are not needed.
5fill in blank
hard

Fill all three blanks to call the function calculate_sum with two numbers and store the result.

Bash Scripting
calculate_sum() {
  echo $(($1 + $2))
}

result=$([1] [2] [3])
Drag options to blanks, or click blank then click option'
Acalculate_sum
B5
C7
Dcalculate_sum()
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses in the function call.
Not separating the arguments with spaces.
Trying to call the function without command substitution.