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?


c00kie88Asked:
Who is Participating?
 
agriesserConnect With a Mentor Commented:
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
 
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
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

 
omarfaridCommented:
then it should work, you try to export the variable

count=`ps | grep -v grep | grep sh | wc -l` ; export count
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
All Courses

From novice to tech pro — start learning today.