Bird
0
0

You want to run a script backup.sh that requires root permissions. Which command correctly runs it with sudo and ensures the script's environment variables are preserved?

hard📝 Application Q15 of 15
Linux CLI - Users and Groups
You want to run a script backup.sh that requires root permissions. Which command correctly runs it with sudo and ensures the script's environment variables are preserved?
Asudo ./backup.sh
Bsudo -E ./backup.sh
Csudo -u root ./backup.sh
Dsudo --preserve-env=ALL ./backup.sh
Step-by-Step Solution
Solution:
  1. Step 1: Understand environment preservation with sudo

    By default, sudo resets environment variables for security. The -E flag preserves the user's environment.
  2. Step 2: Evaluate options for preserving environment

    sudo -E ./backup.sh uses -E which preserves environment variables. sudo --preserve-env=ALL ./backup.sh uses a longer form but --preserve-env=ALL is less common and may not be supported everywhere.
  3. Final Answer:

    sudo -E ./backup.sh -> Option B
  4. Quick Check:

    sudo -E preserves environment variables [OK]
Quick Trick: Use sudo -E to keep environment variables [OK]
Common Mistakes:
MISTAKES
  • Forgetting environment variables reset by sudo
  • Using sudo without -E loses variables
  • Confusing -u root with environment preservation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes