Bird
0
0

What will be the output of the following commands?

medium📝 Command Output Q4 of 15
Linux CLI - Users and Groups
What will be the output of the following commands?
su - alice -c 'echo $USER'
Aempty string
Balice
Ccurrent user
Droot
Step-by-Step Solution
Solution:
  1. Step 1: Understand variable expansion in su -c

    The command inside quotes is run by a new shell as user alice, so $USER expands to alice inside that shell.
  2. Step 2: Recognize quoting effect

    Single quotes prevent expansion by the original shell, so $USER is passed literally to the new shell, which expands it to alice.
  3. Final Answer:

    alice -> Option B
  4. Quick Check:

    su -c runs command as user, so $USER reflects that user [OK]
Quick Trick: Single quotes prevent expansion by original shell; new shell expands $USER [OK]
Common Mistakes:
  • Expecting $USER to expand to alice before su runs
  • Confusing single and double quotes
  • Assuming su changes parent shell variables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes