Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Say I have the following bash script:

#!/bin/bash

echo $( whoami )

This is what it outputs with and without sudo:

alix@netbook:~$ ./test.sh 
alix
alix@netbook:~$ sudo ./test.sh 
root

The script executes several commands that require superuser priviledges, but I also want to add the original executing user to a group. Is there any command that returns alix if I run sudo ./test.sh?

share|improve this question
    
Just noticed that this would better fit Unix.SE, feel free to migrate if needed. –  Alix Axel Jan 27 '13 at 11:56
add comment

1 Answer 1

Found the solution in a related answer:

#!/bin/bash

echo $( whoami )
echo $SUDO_USER

And the output:

alix@netbook:~$ ./test.sh 
alix

alix@netbook:~$ sudo ./test.sh 
root
alix
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.