各位大佬,问个shell问题。
我要批量关闭占用某个端口的进程,执行下面代码
lsof -i:4237 | awk '{if (NR>1){print $2}}' | xargs kill -9
如果4237没有相关进程,
sof -i:4237 | awk '{if (NR>1){print $2}}' 就为空,导致管道后面的xargs kill -9操作缺少参数报错
怎么判断管道输出是否为空?
需求:要实现如果isof -i:4237 | awk '{if (NR>1){print $2}}' 为空,管道后面的xargs kill -9就不执行。
lsof -i:4237 | awk '{if (NR>1){print $2}}' | xargs -r kill -9
xargs --help就有的东西
Please see also the documentation at http://www.gnu.org/software/findutils/.
You can report (and track progress on fixing) bugs in the "xargs"
program via the GNU findutils bug-reporting page at
https://savannah.gnu.org/bugs/?group=findutils or, if
you have no web access, by sending email to bug-findutils@gnu.org.
nice 谢谢