in reply to Get the currently logged in User name

I have to get the user name of the currently login user name instead of some other name.

You seem to operate under the premise that all times, there is exactly one user logged in in an interactive session. That isn't the case, there could be none, or many different ones. What should happen in such a case?

You might also benefit from telling us what your bigger picture is, your question sounds like an XY Problem.

In lack of better ideas, you could parse the output for last to get a list of logged-in users, but there could be better solutions for your overall problem.

  • Comment on Re: Get the currently logged in User name