[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Assign wc-l value to variable

Posted on 2008-10-12
6
Medium Priority
?
1,162 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 375 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.

649 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