Recall & Review
beginner
What is a function in bash scripting?
A function is a named block of code that performs a specific task and can be called multiple times in a script to avoid repetition.
Click to reveal answer
beginner
How do you call a function named
greet in bash?Simply write the function name alone:
greet. Parentheses are not used when calling functions in bash.Click to reveal answer
intermediate
What happens if you call a function before defining it in a bash script?
Bash will give an error because the function must be defined before it is called in the script.
Click to reveal answer
beginner
How can you pass arguments to a bash function?
You pass arguments by writing them after the function name when calling it. Inside the function, use
$1, $2, etc., to access them.Click to reveal answer
intermediate
What is the difference between calling a function with and without parentheses in bash?
In bash, calling a function with or without parentheses is not the same. You call a function by its name without parentheses, e.g.,
func. Using parentheses like func() is a syntax error.Click to reveal answer
How do you call a function named
hello in bash?✗ Incorrect
In bash, you call a function simply by writing its name.
What will happen if you call a function before defining it in a bash script?
✗ Incorrect
Bash requires functions to be defined before they are called, or it will throw an error.
How do you access the first argument passed to a bash function?
✗ Incorrect
Inside a bash function, the first argument is accessed using $1.
Which of these is a valid way to call a function named
myfunc?✗ Incorrect
Calling a function with parentheses like myfunc() is valid in bash.
Can you call a bash function without parentheses?
✗ Incorrect
In bash, parentheses are optional when calling functions.
Explain how to define and call a function in bash with an example.
Think about how you write a function and then use its name to run it.
You got /3 concepts.
Describe how to pass and access arguments inside a bash function.
Arguments are like inputs you give when calling the function.
You got /3 concepts.