Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1180
  • Last Modified:

Assign wc-l value to variable

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
c00kie88
Asked:
c00kie88
1 Solution
 
omarfaridCommented:
which sell are you using?

This should work for sh/ksh/bash

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

0
 
c00kie88Author Commented:
I'm using bourne shell and o/s sun solaris
0
 
omarfaridCommented:
then it should work, you try to export the variable

count=`ps | grep -v grep | grep sh | wc -l` ; export count
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
agriesserCommented:
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
 
TintinCommented:
You don't even need wc.  You can do

count=`ps |grep -c "[s]h"`
0
 
peter991Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now