1

What I have:

alias killport='sudo kill -9 `sudo fuser -n tcp $1 2> /dev/null`'

Problem:

Running e.g. killport 8000 doesn't appear to work, though. However, simply running...

sudo kill -9 `sudo fuser -n tcp 8000 2> /dev/null` 

... DOES work. I can't figure out where I'm messing up.

The major difference between the working and non-working versions as far as I can see is that the aliased version involves a variable, and is executed by the shell for me.... But maybe someone has seen this kind of problem before and knows right where to look.

Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
Brian Peterson
  • 619
  • 1
  • 7
  • 12

1 Answers1

4

You should use a function instead an alias, becaue aliases don't support parameters, make something like that:

killport(){ 

sudo kill -9 $(sudo fuser -n tcp $1 2> /dev/null);

}

Now put this function in your bash configuration file, eg ~/.bashrc and then run:

source  ~/.bashrc

And you're done

HTH

sebelk
  • 4,209
  • 10
  • 35
  • 54