0

I am looping through folders with Java applications and getting the config file for each.

app1/config.yml

app2/config.yml

etc.

I then pull the port from this config file by using:

port= cat app1/config.yml | grep 90 | cut -d: -f2

I want to use the port to kill the application, I did find this code that does half of what I want it to do:

kill $(sudo lsof -t -i:4990)

I want to use the variable stored in port to execute the kill command, but I can't get it to work, what is the correct way to use the command, I have tried multiple ways:

kill $(sudo lsof -t -i:$port)
kill $(sudo lsof -t -i:port)
kill $(sudo lsof -t -i:"$port")
kill $(sudo lsof -t -i:'$port')

But none of these work, I keep getting errors.

Any help would be appreciated

Community
  • 1
  • 1
  • The first and third should both have worked. Why would you expect the last to work, don't you know the difference between single and doule quotes in the shell? – Barmar Oct 08 '15 at 10:52

1 Answers1

0

You're not setting port correctly, you left out the $(...) around the command.

port=$(cat app1/config.yml  | grep 90 | cut -d: -f2)
kill $(sudo lsof -t -i:$port)
Barmar
  • 741,623
  • 53
  • 500
  • 612