Killing of multiple processes error

view story

http://stackoverflow.com – Can someone tell me why this sometimes fails: if [ $(pgrep -f agent.jar | wc -l) -gt 1 ]; then kill $(pgrep -f agent.jar | grep -v $(pgrep -of agent.jar) | sort -n | uniq | awk '{printf $1" "}'); fi The goal of this portion of code is to: Check if duplicate processes exist. Note how I reference the .jar file instead of java incase other java apps are running If duplicates are detected, it gets the process ids of the most recent duplicates (ie leaving out the original) and attempts to kill the duplicates. The code works great. It detects the duplicates and kills them, but sometimes it (HowTos)