LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 08: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, 08:27 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

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


The result is in $?

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

Cheers,
Tink
 
Old 03-18-2007, 03: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, 12:42 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

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


Cheers,
Tink
 
Old 03-20-2007, 08: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, 12:46 AM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

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


Cheers,
Tink
 
  


Reply

Tags
bash, who



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 07:19 PM
Require Linux/Perl equivalent command for windows Command alix123 Programming 7 08-19-2005 02:23 AM
Redirecting output to a command-line argument of another command madiyaan Linux - Newbie 1 02-19-2005 04:35 PM
Key stroke/command to shut down x and go into the command prompt screen? Fear58 Linux - General 1 07-14-2004 07:14 PM
Where is Command line utility for Cups and command tutorial mossy Linux - Software 8 01-16-2004 12:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:26 AM.

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
Open Source Consulting | Domain Registration