[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: kill with regex?



On Sun, Jan 19, 2003 at 03:40:29PM +0000, Hugh Saunders wrote:
> ps x gives a list of xine's which i would like to kill
> 
> 1609 ?        S      0:01 xine /dev/hdc
> 1610 ?        S      0:00 xine /dev/hdc
> 1618 ?        S      0:00 xine /dev/hdc
> 1619 ?        S      0:00 xine /dev/hdc
> 1620 ?        S      0:00 xine /dev/hdc
> 
> tried
> kill 16[1234567890]* 
> 
> which returned
> bash: kill: 16[1234567890]*: no such pid
> 
> 1) is the regexp correct to match the pids of the processes?

bash doesn't understand regexps in general, it understands shell
wildcards. The type you're trying to use expand over filenames, not
process ids; you cannot kill processes by wildcard.

You could use 'kill 16{09,10,18,19,20}', although that's not exactly
much of an improvement. Better would be:

  ps hx -o pid,cmd | sed -e 's/^ *//; s/ .*//'

... see if the output looks sensible, then:

  kill `ps hx -o pid,cmd | sed -e 's/^ *//; s/ .*//'`

-- 
Colin Watson                                  [cjwatson@flatline.org.uk]



Reply to: