LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Simple Bash Script (https://www.linuxquestions.org/questions/programming-9/simple-bash-script-270962/)

dmedici 12-27-2004 07:53 PM

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!

kilgoretrout 12-27-2004 08:12 PM

$ who | grep [whoami]

dmedici 12-27-2004 09:10 PM

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?

kilgoretrout 12-28-2004 12:16 AM

Try this:

$ who | grep `whoami`

those are backward single quotes around whoami which is on the same key as the ~ key.

dmedici 12-29-2004 05:33 PM

OK, that fix with the tic marks worked! Again, thank you very much! Very fast response!

dmedici 12-29-2004 07:00 PM

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?

kilgoretrout 12-30-2004 02:46 AM

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.

bigearsbilly 12-30-2004 04:24 AM

how about ?
Code:

ps -u username
billy

dmedici 12-30-2004 07:55 PM

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

bigearsbilly 12-31-2004 03:48 AM

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.