Bash – An alias for a command to kill stopped jobs

aliasbashquotingshell

I wanted to add an alias to my .bashrc so that I could kill all stopped jobs with a command like kill_stopped. I am aware that kill `jobs -p` can be used to accomplish this but I'd rather have an easier-to-remember alias for convenience sake. So I added this line to my .bashrc:

alias kill_stopped="kill `jobs -p`"

However, when I run it I get a message about the usage of the kill command. To make sure it was being run properly I ran echo "kill `jobs -p`" in the shell and got back "kill <some number>" whenever I had a stopped process. Can anyone help me fix this?

Best Answer

You were close, but you should use single quotes, not double quotes:

kill_stopped='kill `jobs -p` '

Backticks are expanded inside double quotes, so it was running jobs -p at the time you defined the alias, not when you used it.

Related Question