Re:Bash Shell Awesomeness - Mass Killing Processes (On Ubuntu)
by ilyak on Thursday August 06, 2009 @08:12AM
(#745277)
He should really use awk instead of cut.
or killall
and for awesomeness, he should use zsh.
bash is what you use for mediocrity.
[ Parent
| on HN ]
Re:Bash Shell Awesomeness - Mass Killing Processes (On Ubuntu)
by ajross on Thursday August 06, 2009 @11:51AM
(#745719)
Who modded that down? He really should be using awk instead of cut. It has better readability: "{print $2}" to print the second field vs. a set of magic numbers denoting a character field. It's vastly easier to write (again, the "second field" is intuitive). It's also more generally useful, meaning that it's a better tool to know; cut is very primitive.
That said, there are better ways still to solve this problem. Some of them were detailed above. One that wasn't was the fact that GNU ps has lots of filtering options itself, in this case:
ps -eo pid -U 1002
Does the work of the grep and cut from the original for you.
Re:Bash Shell Awesomeness - Mass Killing Processes (On Ubuntu)
by xelfer on Thursday August 06, 2009 @09:44AM
(#745419)
Why awk instead of cut?
Re:Bash Shell Awesomeness - Mass Killing Processes (On Ubuntu)
by ilyak on Thursday August 06, 2009 @10:38AM
(#745539)
awk treats input as lines and columns, therefore it would be more accurate than cut that treats input as lines and characters.
You don't want charaters this to that, what you do want is column 2.