比较shell中的两个数字

时间:2017-09-26 13:34:18

标签: shell sh

如何比较我的脚本中的数字:

#!/bin/sh
service=myservice

if [ $(ps | grep -v grep | grep $service | wc -l) > 0 ]  
then
  echo "$service is running!!!"
else
  echo "$service is NOT running!!!"
fi

以上不起作用

2 个答案:

答案 0 :(得分:0)

使用git bash:

@Override public boolean dispatchKeyEvent(KeyEvent event) {

     Log.i("key pressed", String.valueOf(event.getKeyCode()));
     if(event.getKeyCode()==KeyEvent.KEY_A/*select required keycode*/){

        //perform required  task

     }
     return super.dispatchKeyEvent(event); 
}

答案 1 :(得分:0)

感谢@anubhava,我制作了这个剧本

#!/bin/sh
service=myService

if pgrep "$service" > /dev/null
then
  echo "$service is running!!!"
else
  echo "$service is NOT running!!!"
fi