?? as already answered: ps ax | awk '/[/]slapd /{n++} END{print n}' searching '[s]lapd' will avoid grep "auto-matching", but would still return commands like "vim /etc/slapd.conf" or ./myscript-slapd about pgrep, like the usual grep, it needs a better expression than the process name, otherwise it would return the same results as a grep
however, a perfect match may be done looking for the exact path ('[/]usr/local/bin/slapd '), but would still fail when, for ex. running `objdump /usr/local/bin/slapd -x' also, if you want to count the number of outputed lines, using [p]grep and wc makes two processes, while awk can do it all alone. awk ftw! On Wed, Jan 12, 2011 at 3:17 PM, <four.harris...@googlemail.com> 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-unsubscr...@freebsd.org" > > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to " > freebsd-questions-unsubscr...@freebsd.org" > -- Samuel Martín Moro {EPITECH.} 2011 CamTrace S.A.S "Nobody wants to say how this works. Maybe nobody knows ..." Xorg.conf(5) _______________________________________________ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"