problem with shell script
David Scheidt
dscheidt at panix.com
Wed Jan 12 15:58:37 UTC 2011
On Jan 12, 2011, at 10:43 AM, Samuel Martín Moro wrote:
> On W
>>
>>>> If I run in the following shell script :
>>>>
>>>> #!/bin/sh
>>>> SD=0
>>>> SD=`ps -ax | grep slapd | grep -v grep | wc -l`
>>>> echo $SD
>>>>
>>>> the result is 3 !!!
>>>>
>>>
>> ps ax | grep "[/]slapd " | wc -l
>>
> ps ax | awk '/[/]slapd /{n++} END{print n}'
> sorry...
>
>> may not fix the problem
>> but still cleaner
ps ax | grep [s]lapd | wc -l
The [] creates a one-character class that doesn't match the regex. Easier to type and grep should be a bit faster.
More information about the freebsd-questions
mailing list