Logged in user

To determine the currently logged-in user: username=$(ls -l /dev/console | awk '{ print $3 }')

Note that if you are writing a script for use with a login or logout policy, it is better (and simpler) to use $3 instead.