I have redircted my ouput using /dev/null in bash script but it is still throwing an error. Code is following
ps -p $proc | fgrep $proc> /dev/null
if [ $? -ne '0' ] ; then
......
fi
below is error
error: list of process IDs must follow -p
Usage:
ps [options]
Try 'ps --help <simple|list|output|threads|misc|all>'
or 'ps --help <s|l|o|t|m|a>'
for additional help text.
For more details see ps(1).
Usage: fgrep [OPTION]... PATTERN [FILE]...
Try 'fgrep --help' for more information.
How can I suppress this error without affecting $? output?
$proc
is empty before using it. – Lambert May 27 '15 at 6:26ps
for aPID
using-p
thegrep
seems unnecessary. - You can do (for example):ps -p "$pid" >/dev/null 2>&1 || echo error
, or:if ps -p "$pid" >/dev/null 2>&1 ; then echo okay ; else echo error ; fi
. – Janis May 27 '15 at 6:40$proc
? If so then usetest -n "$proc" && kill -0 "$proc"
– roaima May 27 '15 at 7:12