Linux – Concatenate variable in string bash

bashcommand-line-interfacelinux

I want to kill a process in specified port (variable)

export PORT=3030
netstat -ntlp | awk '$4~/:*${PORT}$/{gsub(/\/.*/,"",$NF);cmd="kill -9 "$NF;system(cmd)}'

but variable PORT doesn't get in the command.

Best Answer

use lsof for this task:

PORT=3030
kill $(lsof -t -ni:$PORT)