Solved

Assign wc-l value to variable

Posted on 2008-10-12
6
1,099 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 …
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
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…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

932 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now