xargs在shell的执行不能为空需要先判断

PID=`jps -l | grep office |grep -v 'grep'| awk '{print $1}' | xargs`
if [ "$PID" ]
then
echo "正在kill进程"
kill -9 $PID
else
echo "没有进程需要kill"
fi

原文地址:https://www.cnblogs.com/cheyunhua/p/12058460.html