How is it that I've been writing shell scripts for over 15 years now to automate processes, and I've only just discovered $SUDO_USER today? I feel like that's a MASSIVE oversight.

@twann @mike can either of you provide a link, or personal clarification what that is and how to use it?

@RyuKurisu @twann @mike
Create a script like this,

[ $SUDO_USER ] && user=$SUDO_USER || user=`whoami`
echo -en "$user"

Then run it as a normal user and then with sudo and see what happens ;)



@hakerdefo @RyuKurisu @twann @mike Just to golf things a little,

echo ${SUDO_USER:-$USER} running as $USER

Sign in to participate in the conversation

Fosstodon is an English speaking Mastodon instance that is open to anyone who is interested in technology; particularly free & open source software.