2

My script to kill the process contains just this

#!/bin/sh

kill -SIGKILL 3590

I get ./xx.sh: line 3: kill: SIGKILL: invalid signal specification

But the same command working fine in the shell and kill -9 3590 working fine in the script as well.

3
  • 1
    Drop the SIG: kill -KILL 3590 Commented Dec 15, 2014 at 3:12
  • Great!. It works.... Why was that? Commented Dec 15, 2014 at 3:15
  • 'They' decided that forcing users to write SIG was a bad idea (probably correct) and didn't consider making the SIG optional (perhaps a less good idea). Also, kill in Bash is a built-in; see Bash POSIX mode; one of the bullets identifies the SIG prefix as being supported by bash and not by sh. The external command probably doesn't support the SIG prefix. Commented Dec 15, 2014 at 3:24

1 Answer 1

2

If the script is behaving differently from the same command in a terminal, it's probably because they're using two different shells.

Just a guess, here, but I'm going to assume that shell in your terminal is bash and /bin/sh points to something else. Try changing the shebang line to #!/bin/bash.

Sign up to request clarification or add additional context in comments.

1 Comment

To go with this, bash makes kill a shell builtin (to allow you to kill a process even if the process table is too full to create a process for running /bin/kill), but kill is not required to be a builtin according to the POSIX spec. (Oops, this pretty much just repeats what Jonathan Leffler said in a question comment.)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.