Shell 相同的命令给出不同的输出
我正在尝试执行以下命令:Shell 相同的命令给出不同的输出,shell,Shell,我正在尝试执行以下命令: ps -e|grep some-process-name|grep -v grep|awk '{print $1}'|grep -v $$ 它给出了进程名为“some process name”的进程的pid 但是当我在shell脚本中使用相同的长命令时,进程名作为命令行参数传递并通过“$1”使用,我在输出中得到两个PID PIDS=$(ps -e|grep $1|grep -v grep|awk '{print $1}'|grep -v $$) echo $PI
ps -e|grep some-process-name|grep -v grep|awk '{print $1}'|grep -v $$
它给出了进程名为“some process name”的进程的pid
但是当我在shell脚本中使用相同的长命令时,进程名作为命令行参数传递并通过“$1”使用,我在输出中得到两个PID
PIDS=$(ps -e|grep $1|grep -v grep|awk '{print $1}'|grep -v $$)
echo $PIDS
这是什么原因呢?有什么建议吗?我在Ubuntu 12.04上的bash 4.0上没有看到这种行为。 pgrep在您的平台上可用吗? pgrep某些进程名称应该可以为您提供帮助