hobby2273 发表于 2013-01-12 19:04

简单的shell, 输出有点奇怪, 高人给看看

Shell脚本如下:

#!/bin/ksh
SCRIPTNAME=`/bin/basename $0`;
SID=$1;
proccnt=`ps -ef |grep $SCRIPTNAME |grep $SID |grep -v grep |wc -l`;
echo "output from: ps -ef |grep $SCRIPTNAME |grep $SID |grep -v grep |wc -l"
ps -ef |grep $SCRIPTNAME |grep $SID |grep -v grep |wc -l
echo "echo proccnt"
echo $proccnt;
if [ $proccnt -gt 1 ]
then
    echo "Another $SCRIPTNAME is running. Abort."
    proccnt=`ps -ef |grep $SCRIPTNAME |grep $SID`
    echo "$proccnt"
    exit;
else
    echo 'proccnt<=1';
fi

输出如下:

svr:elcaro:$ /tmp/test1.sh eddy
output from: ps -ef |grep test1.sh |grep eddy |grep -v grep |wc -l
1
echo proccnt
2
Another test1.sh is running against the same DB. Abort.
elcaro   22231 188603 05:48 pts/0    00:00:00 /bin/ksh /tmp/test1.sh eddy
elcaro   22244 222310 05:48 pts/0    00:00:00 /bin/ksh /tmp/test1.sh eddy
svr:elcaro:$

为何直接ps出来的值是1, 赋给一个变量之后就变成2了呢.
高手赐教.

页: [1]
查看完整版本: 简单的shell, 输出有点奇怪, 高人给看看