unix - How do you write a Fish function that kills a server on a specified port? -


i porting zsh setup fish. i'm struggling arguments in fish, though.

function kill_server      lsof -i tcp:$argv | awk '/listen/{print $argv[1]}' | xargs kill -9      if $argv !== dev 2>null        echo "port" $argv "found , killed."      end end 

i've tried using switch statements, not sure how check regex(?) of port numbers.

you want

function kill_server --argument port      pid in (lsof -i tcp:$port | awk '/listen/{print $2}')          echo -n "found server port $port pid $pid: "          kill -9 $pid; , echo "killed."; or echo "could not kill."      end end 

the $2 in awk body not fish variable, belongs awk.


Comments