Post AAQOponIB41i70vU2q by brejoc@fosstodon.org
 (DIR) More posts by brejoc@fosstodon.org
 (DIR) Post #AAOQCepN6sR5V4Qw7M by mike@fosstodon.org
       2021-08-16T19:50:17Z
       
       0 likes, 0 repeats
       
       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.
       
 (DIR) Post #AAOQRlYmMSuciwsPqK by twann@fosstodon.org
       2021-08-16T19:53:00Z
       
       0 likes, 0 repeats
       
       @mike wow I didn't know either
       
 (DIR) Post #AAOXpBsXNHjUgoEdzk by RyuKurisu@fosstodon.org
       2021-08-16T21:11:55Z
       
       0 likes, 0 repeats
       
       @twann @mike can either of you provide a link, or personal clarification what that is and how to use it?
       
 (DIR) Post #AAOXpCMfZFpsCGKhxg by mike@fosstodon.org
       2021-08-16T21:15:42Z
       
       0 likes, 0 repeats
       
       @RyuKurisu Sure. Here's a script:#!/usr/bin/shecho This is a script.echo $SUDO_USER ran it.If you run this as yourself, the output is:This is a scriptran it.If you run it with sudo, the output is:This is a script<username> ran it.Where <username> is the account name you ran the script from. So, if my username is mike, it would say "mike ran it". This really helps out with things like logging.@twann
       
 (DIR) Post #AAOuvwvpdvC5Izy5Sq by thorn@fosstodon.org
       2021-08-17T00:26:37Z
       
       0 likes, 0 repeats
       
       @RyuKurisu @twann @mike it's in the manpage for sudo
       
 (DIR) Post #AAOuvxS5hyzwv33qkK by mike@fosstodon.org
       2021-08-17T01:34:38Z
       
       0 likes, 0 repeats
       
       @thorn It must be a "new" man page. :blobfoxfacepalm: @RyuKurisu @twann
       
 (DIR) Post #AAP9FOYYYfgXqGFQ9Y by hund@fosstodon.org
       2021-08-17T04:14:58Z
       
       0 likes, 0 repeats
       
       @mike I learned about -n last year or so. That was life changing for me.
       
 (DIR) Post #AAP9PJgdWCZRdPl3dA by hund@fosstodon.org
       2021-08-17T04:16:34Z
       
       0 likes, 0 repeats
       
       @mike I learned about -e last year or so. That was life changing for me.
       
 (DIR) Post #AAP9U9fyAKIA2DklF2 by hund@fosstodon.org
       2021-08-17T04:17:43Z
       
       0 likes, 0 repeats
       
       @mike I learned about -e last year or so. That was life changing for me.```-e      Exit  immediately  if a pipeline (which may consist of a single simple command),  a subshell command enclosed in parentheses, or one of the commands executed as part of a command list enclosed by braces (see SHELL GRAMMAR above) exits with a non-zero  status. ```
       
 (DIR) Post #AAPR9C4tq0TKZvZJs8 by RyuKurisu@fosstodon.org
       2021-08-17T07:35:34Z
       
       0 likes, 0 repeats
       
       @mike @thorn @twann another nicety might be $SUDO_PROMPT: Used as the default password prompt unless the -p option was specified.
       
 (DIR) Post #AAQOponIB41i70vU2q by brejoc@fosstodon.org
       2021-08-17T18:44:18Z
       
       0 likes, 0 repeats
       
       @mike huh… didn’t know that exists. Thanks!
       
 (DIR) Post #AATBj5SV6X79q7Xb3A by dokin@fosstodon.org
       2021-08-19T03:01:13Z
       
       0 likes, 0 repeats
       
       @mike Well, I didn't know either. And after I checked the man page of sudo, I found there are many $SUDO_* environment variables.SUDO_ASKPASS, SUDO_COMMAND, SUDO_EDITOR, SUDO_GID, SUDO_PROMPT, SUDO_PS1, SUDO_UID and this SUDO_USER.
       
 (DIR) Post #AAVP0EI3ZAAEgF37Fg by RyuKurisu@fosstodon.org
       2021-08-20T04:39:47Z
       
       0 likes, 0 repeats
       
       @mike BTW I find it funny that I learn something about `sudo` whereas I'm starting to use `doas` on Alpine Linux :thaenkin: Maybe I should check out the manpage of `doas` to learn all its niceties? #LearnAllTheThings :allthethings: