hi guys
Was wondering if you can help me.
For my scripts i usually use below for the currently logged in user
ls -l /dev/console | cut -d " " -f4
this returns tkimpton@rufusleonard.hq
Im trying to work out how to strip out @rufusleonard.hq so i am left with tkimpton.
Any ideas?
Best answer by mm2270
Do you get a better result with the following?-
/usr/bin/who | awk '/console/{ print $1 }'
If not, you can use your command and send it through another cut like this-
| cut -d@ -f1
That should leave you with everything from before the @ symbol, meaning "tkimpton'
OMG wow that if friggin awesome.
Thank you very much
went on a bender last night and my brain has b een hitting a brick wall ;)
following in the "1001 ways to do" X tradition: ```who | grep console | awk '{print $1}'```
/dev/console does seem to be a bit more reliable, sometimes when logging out one user and logging in a new one who on the console can produce less than consistent results in my experience anyway...
Yet another way which avoids grep and awk:
stat -f "%Su" /dev/console
Thanks guys :)
You can also read the lastUser key from com.apple.loginwindow.plist
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
Sorry, we're still checking this file's contents to make sure it's safe to download. Please try again in a few minutes.
Sorry, our virus scanner detected that this file isn't safe to download.