Solved

Assign wc-l value to variable

Posted on 2008-10-12
6
1,123 Views
Last Modified: 2008-11-24
Hi all,

how do i assign wc value to a variable?

ps | grep -v grep | grep "sh" | wc -l

I tried :

count=`ps | grep -v grep | grep "sh" | wc -l`
count=$(ps | grep -v grep | grep "sh" | wc -l)

but none of them works

is there any other method?


0
Comment
Question by:c00kie88
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 40

Expert Comment

by:omarfarid
ID: 22696746
which sell are you using?

This should work for sh/ksh/bash

count=`ps | grep -v grep | grep sh | wc -l`

0
 

Author Comment

by:c00kie88
ID: 22696747
I'm using bourne shell and o/s sun solaris
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 22696761
then it should work, you try to export the variable

count=`ps | grep -v grep | grep sh | wc -l` ; export count
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Accepted Solution

by:
agriesser earned 125 total points
ID: 22696962
You do not need the `grep -v grep` when using the following trick:
count=`ps | grep [s]h | wc -l`

Open in new window

0
 
LVL 48

Expert Comment

by:Tintin
ID: 22698715
You don't even need wc.  You can do

count=`ps |grep -c "[s]h"`
0
 
LVL 6

Expert Comment

by:peter991
ID: 22702520
What are you trying to achieve?
Number of logged in or just processes containing 'sh'?

You also got the commands 'who' 'whodo' and 'last'...

Regards.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question