Simple Bash Script
Hi all!
Trying to write a very simple Bash script as I learn how to work in Bash... One line needs me to: "display any results from the who command about the current user only" Can someone tell me how to do this? Many thanks in advance! |
$ who | grep [whoami]
|
Thank you for the very fast reply! It worked when I logged in as root, but then I went to another shell, logged in as TEST, and unfortunately it didn't work there, although typing in WHO as TEST gave me results. Any other possibilities for that line?
|
Try this:
$ who | grep `whoami` those are backward single quotes around whoami which is on the same key as the ~ key. |
OK, that fix with the tic marks worked! Again, thank you very much! Very fast response!
|
One more question if I may - I need to do the same thing I did with the WHO command but with the ps command. I tried adding that line below the who | grep `whoami` with ps substituted for who but it didn't take. Any ideas?
|
Try:
$ ps -ef | grep `whoami` See man ps. The "ef" switch is necessary to get the user name associated with the process and grep can work from that output. |
how about ?
Code:
ps -u username |
Thanks to both of you for the quick replies - both solutions work but in slightly different ways - Kilgore's has slightly more info in the output than billy's, but they are both pretty much what I was looking for. Great job! Really helped me a lot!
D |
if you read the man page for ps
you'll see you can tailor the output to exactly the fields you want using an option string. regards, billy |
All times are GMT -5. The time now is 10:55 AM. |