From owner-freebsd-questions@FreeBSD.ORG Wed Jan 12 16:42:32 2011 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 60D88106566B for ; Wed, 12 Jan 2011 16:42:32 +0000 (UTC) (envelope-from rhml@kibug.org) Received: from mail-pw0-f54.google.com (mail-pw0-f54.google.com [209.85.160.54]) by mx1.freebsd.org (Postfix) with ESMTP id 3CC9B8FC13 for ; Wed, 12 Jan 2011 16:42:31 +0000 (UTC) Received: by pwi10 with SMTP id 10so136441pwi.13 for ; Wed, 12 Jan 2011 08:42:30 -0800 (PST) Received: by 10.142.237.20 with SMTP id k20mr36737wfh.5.1294849070338; Wed, 12 Jan 2011 08:17:50 -0800 (PST) Received: from millet.bsd.lab (y047061.ppp.asahi-net.or.jp [118.243.47.61]) by mx.google.com with ESMTPS id q13sm1041051wfc.5.2011.01.12.08.17.49 (version=SSLv3 cipher=RC4-MD5); Wed, 12 Jan 2011 08:17:49 -0800 (PST) Message-ID: <4D2DD47B.7030302@kibug.org> Date: Thu, 13 Jan 2011 01:19:07 +0900 From: Ryuichiro Hara User-Agent: Mozilla/5.0 (X11; U; FreeBSD amd64; ja-JP; rv:1.9.2.13) Gecko/20101221 Thunderbird/3.1.7 MIME-Version: 1.0 To: freebsd-questions@freebsd.org References: <4D2DB449.6070901@esiee.fr> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: problem with shell script X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Jan 2011 16:42:32 -0000 (2011/01/13 01:00), Warren Block wrote: > On Wed, 12 Jan 2011, Samuel Mart?n Moro wrote: > >> On Wed, Jan 12, 2011 at 3:50 PM, Chad Kellerman >> wrote: >> >>> On Wed, Jan 12, 2011 at 9:01 AM, Frank Bonnet >>> wrote: >>> >>>> I'm in trouble with a simple shell script that give >>>> erroneous value when running ... >>>> >>>> If I run commands interactively everything runs well >>>> >>>>> ps ax | grep slapd | grep -v grep | wc -l >>>> 1 >>>> >>>> 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 >> may not fix the problem >> but still cleaner > > ps axc | grep slapd | wc -l > > is a little neater. > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to > "freebsd-questions-unsubscribe@freebsd.org" hello. i would rather use pgrep(1); pgrep -afl slapd for just counting purpose, pgrep -a slapd | wc -l is enough. i believe it should work all right as expected in `` output, as well.