如何将结果的结果传递给shell中的另一个命令? [英] How to pass results of results to another command in shell?
本文介绍了如何将结果的结果传递给shell中的另一个命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用以下组合 grep
, ls
和 awk
我得到一个列表 pid ,我需要杀:
Using the following combination of grep
, ls
and awk
I get a list of pid that I need to kill:
grep -hP '^\d+$' `ls -lad /dir/*/pid | grep -P '/dir/\d+/pid' | awk '{ print $9 }'`
13234
18972
24322
b $ b
如何在命令组合中添加 kill -9
命令来终止这些进程?
How can I now add kill -9
command to this command combination to kill those processes?
我已经使用`
字符将 awk
结果传递到 grep
命令,所以我认为我不能再次使用它传递给 kill
,正确?
I already using `
characters to pass awk
results to grep
command, so I assume I cannot use it again to pass it to kill
, correct?
推荐答案
除了 Chris Jester-Young好的答案,我会说 xargs
也是这些情况的一个很好的解决方案:
In addition to Chris Jester-Young good answer, I would say that xargs
is also a good solution for these situations:
grep ... `ls -lad ... | awk '{ print $9 }'` | xargs kill -9
就可以了。一起:
grep -hP '^\d+$' `ls -lad /dir/*/pid | grep -P '/dir/\d+/pid' | awk '{ print $9 }'` | xargs kill -9
这篇关于如何将结果的结果传递给shell中的另一个命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文