Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
12-27-2004, 07:53 PM
|
#1
|
|
Member
Registered: Aug 2003
Posts: 57
Rep:
|
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!
|
|
|
|
12-27-2004, 08:12 PM
|
#2
|
|
Senior Member
Registered: Oct 2003
Posts: 2,280
Rep: 
|
$ who | grep [whoami]
|
|
|
|
12-27-2004, 09:10 PM
|
#3
|
|
Member
Registered: Aug 2003
Posts: 57
Original Poster
Rep:
|
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?
|
|
|
|
12-28-2004, 12:16 AM
|
#4
|
|
Senior Member
Registered: Oct 2003
Posts: 2,280
Rep: 
|
Try this:
$ who | grep `whoami`
those are backward single quotes around whoami which is on the same key as the ~ key.
|
|
|
|
12-29-2004, 05:33 PM
|
#5
|
|
Member
Registered: Aug 2003
Posts: 57
Original Poster
Rep:
|
OK, that fix with the tic marks worked! Again, thank you very much! Very fast response!
|
|
|
|
12-29-2004, 07:00 PM
|
#6
|
|
Member
Registered: Aug 2003
Posts: 57
Original Poster
Rep:
|
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?
|
|
|
|
12-30-2004, 02:46 AM
|
#7
|
|
Senior Member
Registered: Oct 2003
Posts: 2,280
Rep: 
|
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.
|
|
|
|
12-30-2004, 04:24 AM
|
#8
|
|
Senior Member
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,211
Rep: 
|
|
|
|
|
12-30-2004, 07:55 PM
|
#9
|
|
Member
Registered: Aug 2003
Posts: 57
Original Poster
Rep:
|
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
|
|
|
|
12-31-2004, 03:48 AM
|
#10
|
|
Senior Member
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,211
Rep: 
|
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
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 02:36 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|