From owner-freebsd-questions@FreeBSD.ORG Thu Jan 13 20:39:49 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 3F3941065670 for ; Thu, 13 Jan 2011 20:39:49 +0000 (UTC) (envelope-from bonomi@mail.r-bonomi.com) Received: from mail.r-bonomi.com (host-120.r-bonomi.com [204.87.227.120]) by mx1.freebsd.org (Postfix) with ESMTP id F13E68FC21 for ; Thu, 13 Jan 2011 20:39:48 +0000 (UTC) Received: (from bonomi@localhost) by mail.r-bonomi.com (8.14.4/rdb1) id p0DKj43V027817; Thu, 13 Jan 2011 14:45:04 -0600 (CST) Date: Thu, 13 Jan 2011 14:45:04 -0600 (CST) From: Robert Bonomi Message-Id: <201101132045.p0DKj43V027817@mail.r-bonomi.com> To: f.bonnet@esiee.fr, freebsd-questions@freebsd.org In-Reply-To: <4D2DB449.6070901@esiee.fr> Cc: 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: Thu, 13 Jan 2011 20:39:49 -0000 > Date: Wed, 12 Jan 2011 15:01:45 +0100 > From: Frank Bonnet > Subject: problem with shell script > > 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 !!! Advice: don't try to 'out-think' the machine -- make it _show_ you what it is doing. Change the script to: SD=`ps -ax | grep slapd | grep -v grep | tee /dev/tty | wc -l` echo $SD I suspect thet the -name- of the script file has 'slapd' in it.