Suppose I have something like
.PHONY: kill-server
kill-server:
kill -9 $(lsof -t -i :9000)
Why it doesn't work and how do I fix this?
Suppose I have something like
.PHONY: kill-server
kill-server:
kill -9 $(lsof -t -i :9000)
Why it doesn't work and how do I fix this?
You could pipe lsof
to xargs
in your makefile:
# Makefile - Version 1
# Send kill to server
kill-server:
lsof -t -i :9000| xargs kill -9
Good grief. So much confusion.
It's very simple: $
is special to make. It introduces a make variable. If you write a recipe (which is a shell script) and you want the shell to see the $
you have to escape it so that make won't expand it as a make variable. That's completely trivial to do, you just write $$
anywhere you want to pass $
to the shell:
.PHONY: kill-server
kill-server:
kill -9 $$(lsof -t -i :9000)
That's it. Done.