LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-17-2007, 09:03 PM   #1
dory550
LQ Newbie
 
Registered: Aug 2006
Location: nyc
Distribution: RedHat ES 4.0
Posts: 7

Rep: Reputation: 0
who command


Hi guys

What Bash script do I use to test the true of false results of the command 'who | grep pts'
how do I assign the results to a variable?
Thank you
Dory
 
Old 03-17-2007, 09:27 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Hi, and welcome to LQ!


The result is in $?

Code:
who | grep pts > /dev/null 2>&1
result = $?

Cheers,
Tink
 
Old 03-18-2007, 04:41 AM   #3
dory550
LQ Newbie
 
Registered: Aug 2006
Location: nyc
Distribution: RedHat ES 4.0
Posts: 7

Original Poster
Rep: Reputation: 0
Tink
echo $? produces 1 or 0

result = $? #produces an error( -bash: results: command not found )

thanks
Dory
 
Old 03-18-2007, 01:42 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Sorry about that; give the spaces around the = a miss.
And yes, 0 is success, 1 is failure.


Cheers,
Tink
 
Old 03-20-2007, 09:06 PM   #5
dory550
LQ Newbie
 
Registered: Aug 2006
Location: nyc
Distribution: RedHat ES 4.0
Posts: 7

Original Poster
Rep: Reputation: 0
Tink
Thank you for your help
Dory
 
Old 03-21-2007, 01:46 AM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
You're welcome, glad it works for you.


Cheers,
Tink
 
  


Reply

Tags
bash, who


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a single command to list all hardware installed (command line)? davee Linux - Hardware 6 02-28-2009 08:19 PM
Require Linux/Perl equivalent command for windows Command alix123 Programming 7 08-19-2005 03:23 AM
Redirecting output to a command-line argument of another command madiyaan Linux - Newbie 1 02-19-2005 05:35 PM
Key stroke/command to shut down x and go into the command prompt screen? Fear58 Linux - General 1 07-14-2004 08:14 PM
Where is Command line utility for Cups and command tutorial mossy Linux - Software 8 01-16-2004 01:24 AM


All times are GMT -5. The time now is 01:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration