1

I have the following in my .bash_profile:

k9 () { for A in $(ps -A | grep $* | sed 's/^\([A-Za-z0-9]*\).*/\1/' ; ) ; do "kill -9  $A"; done  }

The script supposed to grep the var inputed in the command line S* get the PIDs those and execute a kill -9 on each of them. But instead I am getting this:

Machine:~ mach$ k1 Chromium
-bash: kill -9  81922: command not found
-bash: kill -9  82009: command not found
-bash: kill -9  82423: command not found
-bash: kill -9  82424: command not found
-bash: kill -9  82560: command not found
-bash: kill -9  82561: command not found
-bash: kill -9  82563: command not found
-bash: kill -9  82608: command not found
-bash: kill -9  85243: command not found
-bash: kill -9  85248: command not found
-bash: kill -9  85321: command not found

Thanks in advance!

1
  • Consider breaking the script up into multiple lines to make it more readable. Commented Jul 11, 2016 at 17:55

1 Answer 1

2

You don't need to quote the entire command.

k9 () {
  for A in $(ps -A | grep $* | sed 's/^\([A-Za-z0-9]*\).*/\1/' ; ) ; do
    kill -9  "$A"
  done
}
Sign up to request clarification or add additional context in comments.

1 Comment

Worked like a charm. Thanks chepner!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.