bash - system command returns strange value -


i have script

 #!/bin/bash  npid=$(pgrep -f procname | wc -l)  echo $npid  if [ $npid -lt 3 ];then   service procname start;  fi 

when procname running, works fine showing correct number $npid. fails when there isn't procname running. should return zero, returns npid=3, 3. same problem see ps auxw | grep procname | grep -v grep | wc -l well.

something trivially wrong couldn't figure out, suggestions ?

* edit

# returns nothing if therisn't process name poopit running pgrep -f poopit    # in case when no process running, below returns 0 if typed on bash cmd line  pgrep -f poopit | wc -l   # if running, pgrep -f poopit | wc -l 17  # if running, script $npid shows  19 


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -