Bird
0
0

Which sudo option allows you to run a script as root while preserving the user's environment variables?

hard📝 Application Q8 of 15
Linux CLI - Users and Groups
Which sudo option allows you to run a script as root while preserving the user's environment variables?
Asudo -E ./script.sh
Bsudo -i ./script.sh
Csudo -u root ./script.sh
Dsudo --reset-env ./script.sh
Step-by-Step Solution
Solution:
  1. Step 1: Understand environment preservation

    The -E option preserves the user's environment variables when running commands with sudo.
  2. Step 2: Compare options

    -i simulates a login shell resetting environment; -u root changes user but does not preserve environment; --reset-env clears environment variables.
  3. Final Answer:

    sudo -E ./script.sh -> Option A
  4. Quick Check:

    Use -E to keep environment variables with sudo [OK]
Quick Trick: Use sudo -E to preserve environment variables [OK]
Common Mistakes:
MISTAKES
  • Using -i which resets environment
  • Assuming -u root preserves environment
  • Confusing --reset-env as preserving environment

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes