Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 13 Jan 2011 01:51:39 +0900
From:      Ryuichiro Hara <rhml@kibug.org>
To:        Frank Bonnet <f.bonnet@esiee.fr>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: problem with shell script
Message-ID:  <4D2DDC1B.9050408@kibug.org>
In-Reply-To: <4D2DB449.6070901@esiee.fr>
References:  <4D2DB449.6070901@esiee.fr>

next in thread | previous in thread | raw e-mail | index | archive | help
(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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4D2DDC1B.9050408>