Recall & Review
beginner
What does it mean to 'source' a script in Bash?
Sourcing a script means running it in the current shell session so that functions and variables defined in it become available immediately without starting a new shell.
Click to reveal answer
beginner
How do you source a script named
library.sh in Bash?Use the command
source library.sh or the shorthand . library.sh to include the script in the current shell session.Click to reveal answer
beginner
Why use function libraries in Bash scripting?
Function libraries let you reuse code easily by keeping common functions in one file. You can source this file in many scripts to avoid rewriting the same code.Click to reveal answer
intermediate
What happens if you run a script normally instead of sourcing it when you want to use its functions?
Running a script normally starts a new shell, so functions and variables defined inside it won't be available in your current shell session.
Click to reveal answer
intermediate
How can you check if a function library script was sourced successfully?
After sourcing, try calling a function from the library. If it runs without error, the sourcing worked. You can also check if the function is defined using
type function_name.Click to reveal answer
Which command correctly sources a script named
utils.sh?✗ Incorrect
The
source command runs the script in the current shell, making its functions and variables available.What is the main benefit of sourcing a function library script?
✗ Incorrect
Sourcing runs the script in the current shell, so functions and variables become accessible immediately.
If you run
./library.sh instead of sourcing it, what happens to the functions defined inside?✗ Incorrect
Running the script starts a new shell, so functions stay local to that shell and do not affect the current one.
Which symbol is a shorthand for the
source command in Bash?✗ Incorrect
The dot
. is a shorthand for source in Bash.How can you verify if a function named
greet is defined after sourcing a script?✗ Incorrect
The
type command shows if a function or command is defined in the current shell.Explain what sourcing a script means and why it is useful in Bash scripting.
Think about how sourcing affects your current shell session.
You got /4 concepts.
Describe the difference between running a script normally and sourcing it, especially regarding function availability.
Consider where the functions live after each method.
You got /4 concepts.