1、脚本check_nginx.sh的内容如下:

1 #!/bin/bash
2 count=$(ps -ef | grep nginx | grep -v grep | wc -l)
3 sleep 10
4 echo $count

2、执行ps -ef | grep nginx | grep -v grep | wc -l,真实结果为2

shell执行时文件命名导致的错误_bash

shell执行时文件命名导致的错误_字段_02

3、但是执行sh -x check_nginx.sh结果却为4,原因是执行文件的名字包含了匹配的关键字段“nginx”

shell执行时文件命名导致的错误_字段_03