Following is my script \'Infinite.sh\' code, I am running this script in background,Before running this script, i want to kill all previous instances. But this is killing my cur
Simply check if the pid is the same as the one of the running script.
Something like this could work:
#!/bin/bash pids=($(pgrep "$(basename "$0")")) for i in "${pids[@]}" do (( $$ != i)) && kill "$i" done while :; do sleep 1;done ~