Solved

Assign wc-l value to variable

Posted on 2008-10-12
6
1,108 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
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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.

770 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