I’ve never used the $LOGNAME as I didn’t think it was standard enough to script against. But in all the examples I checked, $LOGNAME is set, and set the same as $USER. IF this is ALWAYS true, then I don’t see why it wouldn’t work. But I’m not familiar enough with this variable and why it exists to depend on it.
Thanks for pointing this out. It seems that $USER is usually set but might not be depending on how you start your session. After doing some research, it seems the portable (posix compliant) way is to spawn a subshell running id -u -n, and I like to stay posix compliant