When you want to kill processes, it's a pain in the neck to run , figure out the process ID, and then kill the process. The zap shell script was presented by Brian Kernighan and Rob Pike in their classic book The UNIX Programming Environment . The script uses to pick the processes to kill; you can type extended expressions that match more than one process, such as:
We've reprinted the script by permission of the authors:
This shell version of zap calls another script, pick , shown below.  pick shows each of its command-line arguments and waits for you to type y , q , or anything else. Answering y writes the line to standard output, answering q aborts pick without showing more lines, and any other answer shows the next input line without printing the current one. zap uses to print the first argument (the process ID number) from any ps line you've selected with pick . The inner set of in zap pass pick the output of ps , filtered through egrep . Because the zap script has set the to just a newline, pick gets and displays each line of ps output as a single argument. The outer set of backquotes passes the output of pick , filtered through awk .
If you're interested in shell programming and that explanation wasn't detailed enough, take a careful look at the scripts - they're really worth studying. (This book's shell programming chapters, 44 through 46, may help, too.) Here's the pick script: