Recall & Review
beginner
What is a configuration file in scripting?
A configuration file stores settings or options that a script can read to change its behavior without changing the script code.
Click to reveal answer
beginner
How do you read a simple key-value pair from a configuration file in Bash?
You can use the 'source' command to load the file if it contains valid Bash syntax, or use tools like 'grep' and 'cut' to extract values.
Click to reveal answer
beginner
What does the command 'source config.cfg' do in a Bash script?
It runs the commands inside 'config.cfg' in the current shell, making variables and functions defined there available to the script.
Click to reveal answer
intermediate
Why should configuration files avoid complex commands when used with 'source'?
Because 'source' executes the file as code, complex commands can cause errors or unexpected behavior. Configuration files should only set variables.
Click to reveal answer
intermediate
How can you safely read a configuration file with comments and blank lines in Bash?
Use 'grep' to ignore comments and blank lines, then parse key-value pairs with 'cut' or 'awk' to extract needed values.
Click to reveal answer
Which Bash command loads variables from a configuration file into the current script?
✗ Incorrect
The 'source' command runs the file in the current shell, loading variables and functions.
What is the best format for a configuration file to be sourced by a Bash script?
✗ Incorrect
Bash can easily source files with simple key=value pairs as variable assignments.
How can you ignore comment lines starting with '#' when reading a config file with grep?
✗ Incorrect
The '-v' option inverts match, so lines starting with '#' are excluded.
If a config file has 'PORT=8080', how do you access this value after sourcing it?
✗ Incorrect
After sourcing, variables are available as shell variables accessed with a '$' prefix.
What happens if a config file sourced by Bash contains commands that delete files?
✗ Incorrect
Sourcing runs all commands in the file, so dangerous commands will execute.
Explain how to safely read and use a configuration file in a Bash script.
Think about how the script gets settings without errors.
You got /4 concepts.
Describe the risks of sourcing an untrusted configuration file in Bash.
Consider what happens when code runs unexpectedly.
You got /4 concepts.