Skip to content

Instantly share code, notes, and snippets.

@Flushot
Created November 14, 2013 00:07
Show Gist options
  • Select an option

  • Save Flushot/7458899 to your computer and use it in GitHub Desktop.

Select an option

Save Flushot/7458899 to your computer and use it in GitHub Desktop.
Get user logged into graphical desktop (OSX and Linux)
#!/bin/bash
os=`uname`
user=
if [ "$os" == "Darwin" ]; then
# osx
user=`stat -f '%Su' /dev/console`
elif [ "$os" == "Linux" ]; then
# linux
user=`who -s | awk '/^[^\s]+? :0 / { print $1 }' | head -n1`
fi
echo $user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment