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 reused multiple times in a script.
Click to reveal answer
beginner
Why do we use functions to organize code?
Functions help keep code clean, avoid repetition, and make scripts easier to read and maintain.
Click to reveal answer
beginner
How does using functions save time when writing scripts?
Once a function is written, you can call it many times without rewriting the same code, saving effort and reducing mistakes.
Click to reveal answer
beginner
What is an example of a simple bash function?
Example:
greet() {
echo "Hello, $1!"
}
greet Alice
This prints: Hello, Alice!
Click to reveal answer
beginner
How do functions improve script maintenance?
If you need to change a task, you only update the function once instead of changing the same code in many places.
Click to reveal answer
What is the main benefit of using functions in bash scripts?
✗ Incorrect
Functions let you reuse code blocks without rewriting them, making scripts cleaner and easier to manage.
How do you call a function named 'backup' in bash?
✗ Incorrect
You call a bash function by writing its name followed by any arguments, like: backup
Which symbol is used to define a function in bash?
✗ Incorrect
Parentheses () after the function name define it, for example: myfunc() { commands }
What happens if you change code inside a function?
✗ Incorrect
Changing a function updates its behavior everywhere it is called in the script.
Why is avoiding repeated code important?
✗ Incorrect
Avoiding repeated code helps prevent mistakes and makes scripts easier to update.
Explain in your own words why functions help organize reusable code in bash scripting.
Think about how you might repeat a task many times in a script.
You got /4 concepts.
Describe a simple example of a bash function and how you would use it multiple times.
Try to imagine greeting different people using one function.
You got /4 concepts.