Skip to main content
9 events
when toggle format what by license comment
Jun 27, 2022 at 6:05 comment added G-Man Says 'Reinstate Monica' @Hogcryat: If you're going to abbreviate my name, please abbreviate it as ''G-Man''.
Jun 26, 2022 at 18:37 comment added tearfur @Kusalananda it is just as Reinstate Monica says. It is an improvement to Eric's answer in the case the script was called with sudo (which I know is not the question's original intention). I would have liked to comment under Eric's answer but I don't have enough reputation.
Jun 26, 2022 at 2:08 comment added G-Man Says 'Reinstate Monica' @Kusalananda: OK, now it’s my turn to re-read and re-write/clarify.  Hogcryat’s answer (above) links to Eric James Deiter’s answer, and the explanation is in the first paragraph of Eric’s answer.
Jun 25, 2022 at 22:40 comment added G-Man Says 'Reinstate Monica' @Kusalananda: The explanation is right there in the first paragraph. OK, yes, the script in the question contains multiple sudo commands, so it’s ‘ ‘clearly’ ’ meant to be run by a non-root user. But what if somebody inadvertently runs the script itself under sudo? Then the id command (as used by Tim Cutts) would return “root” and not, as (presumably) desired, the name of the logged-in user.
Jun 25, 2022 at 18:15 comment added Kusalananda Sorry for the tone in my last comment (I just re-read it). What I was fishing for is merely an explanation of the problem that you see and an explanation of your solution, taking into account that since you refer to Tim's answer, you would need to clarify the circumstances that his answer gets it wrong and what "wrong" actually means.
Jun 25, 2022 at 17:55 comment added Kusalananda Note that the script in the question is executed with /bin/sh as the shell. If that shell does not set the USER variable, Tim's code would call id to figure out the username. Under what circumstances would logname get the username right and id get it wrong? Would the shell need to set USER to the wrong username for that to be the case? What do you mean by "not work"? Are you expecting the user to be reported as root or the invoking user in your example?
Jun 25, 2022 at 13:41 review Late answers
Jun 25, 2022 at 22:41
S Jun 25, 2022 at 13:22 review First answers
Jun 30, 2022 at 15:08
S Jun 25, 2022 at 13:22 history answered tearfur CC BY-SA 4.0