But in the macOS Catalina release notes, we have learned that some, yet undefined, future version of macOS will not include the Python, Ruby, and Perl interpreters any more.
This used to be fine, as the python binary shipped with macOS. While this has worked wonderfully and more reliably than other solutions, it always looked inelegant, and added a dependency on the python binary. But there are edge cases, mostly with Fast User Switching, where these methods don’t return the correct user. There are various other solutions to get the current user which use stat, who, or last commands. However, the semi-official, “sanctioned” method has always involved a rather elaborate python one-liner, originally published by Ben Toms: loggedInUser=$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCop圜onsoleUser import sys username = (SCDynamicStoreCop圜onsoleUser(None, None, None) or ) username = ] (username + '\n') ') There are many solutions to get the current logged in user in macOS to use in a shell script. …or, how to deal with deprecated bash and python…