Greg Wooledge wrote:
"$PORT" should be quoted here.
Thanks a lot Greg. So my improved script as following. #!/bin/bash port=$1 if [ -z "$port" ];then echo "usage: $0 port" >&2 exit 1 fi ps=$(lsof -i :"$port" |awk '/LISTEN/ {print $2}') if [ -z "$ps" ];then echo "no this port, or I don't have privilege to list the port" >&2 exit 1 fi ps -efw |grep -v grep |grep "$ps" exit 0 Is it the right one for now? Regards.