The source app.conf command loads variables USERNAME and PORT into the script.
Step 2: Print the variables
The echo command prints the values of USERNAME and PORT, which are 'guest' and '8080'.
Final Answer:
User: guest, Port: 8080 -> Option D
Quick Check:
Variables loaded and printed = C [OK]
Hint: Sourcing sets variables, echo prints their values [OK]
Common Mistakes:
Not sourcing the file before using variables
Expecting variable names printed literally
Confusing syntax causing errors
4. What is wrong with this script snippet that tries to read config.cfg and print a variable?
source config.cfg
echo "Value: $VALUE"
Assuming config.cfg contains VALUE=42, but the output is empty.
medium
A. The script forgot to use 'export' before sourcing
B. The config file has spaces around '=' causing no assignment
C. The variable name is case-sensitive and mismatched
D. The source command is misspelled
Solution
Step 1: Check config file syntax
If the config file has spaces like VALUE = 42, bash treats it as a command, not assignment.
Step 2: Effect on sourcing
Because of wrong syntax, VALUE is not set, so echo prints empty.
Final Answer:
The config file has spaces around '=' causing no assignment -> Option B
Quick Check:
No spaces in var assignment = A [OK]
Hint: No spaces around '=' in config files [OK]
Common Mistakes:
Adding spaces around '=' in variable assignments
Thinking 'export' is needed before sourcing
Ignoring case sensitivity of variable names
5. You want to safely read a config file settings.conf that might contain unsafe commands. Which approach is best to avoid running unwanted code while still getting variable values?
hard
A. Run the config file as a separate script
B. Use source settings.conf directly without checks
C. Manually parse the file line-by-line to extract variable assignments
D. Delete the config file before sourcing
Solution
Step 1: Understand risks of sourcing
Using source runs all commands in the file, which can be unsafe if file is untrusted.
Step 2: Safe alternative
Manually reading lines and extracting only variable assignments avoids executing harmful commands.
Final Answer:
Manually parse the file line-by-line to extract variable assignments -> Option C
Quick Check:
Parse manually to avoid unsafe code = A [OK]
Hint: Parse config lines manually to avoid running code [OK]
Common Mistakes:
Sourcing untrusted config files directly
Running config as a script without validation
Deleting config file instead of securing it
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.