From owner-freebsd-questions@FreeBSD.ORG Wed Jan 12 16:50:25 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 4A3DF106564A for ; Wed, 12 Jan 2011 16:50:25 +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 28D808FC1A for ; Wed, 12 Jan 2011 16:50:24 +0000 (UTC) Received: by pwi10 with SMTP id 10so138243pwi.13 for ; Wed, 12 Jan 2011 08:50:23 -0800 (PST) Received: by 10.142.140.6 with SMTP id n6mr56405wfd.221.1294851023336; Wed, 12 Jan 2011 08:50:23 -0800 (PST) Received: from millet.bsd.lab (y047061.ppp.asahi-net.or.jp [118.243.47.61]) by mx.google.com with ESMTPS id w14sm1071108wfd.18.2011.01.12.08.50.21 (version=SSLv3 cipher=RC4-MD5); Wed, 12 Jan 2011 08:50:22 -0800 (PST) Message-ID: <4D2DDC1B.9050408@kibug.org> Date: Thu, 13 Jan 2011 01:51:39 +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: Frank Bonnet References: <4D2DB449.6070901@esiee.fr> In-Reply-To: <4D2DB449.6070901@esiee.fr> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-questions@freebsd.org 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:50:25 -0000 (2011/01/12 23:01), Frank Bonnet wrote: > Hello > > 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 !!! > > > Any info welcome ! > > _______________________________________________ > 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. it should work as expected in `` output.