Pergunta

I am trying to create an alias for the following command

lsof -i :$1 | awk 'NR!=1 {print $2}' | xargs kill

However I keep getting an error:

lsof: unacceptable port specification in: -i :

I tried different things but I keep failing to pass the port number successfully. How can I pass the port number into this alias?

Foi útil?

Solução

If you need to pass a parameter into a specific position, an alias cannot be done. Instead, create a function:

myfunc() {
   lsof -i :$1 | awk 'NR!=1 {print $2}' | xargs kill
}

If you save it in your ~/.bashrc file you will be able to call it with myfunc parameter.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top