我是 bash 脚本的全明星菜鸟。我的脚本看起来像这样:
#!/bin/bash
pgrep grunt > target.txt
for i in target.txt
do kill $i
echo "killed $i"
done
现在,显然它没有用,我不知道如何让它工作。
我希望此脚本将 pgrep grunt
的输出echo
到文件 target.txt 并从那里读取 PID
并终止这些进程。
最佳答案
回答你的问题:
#!/bin/bash
while read i; do
kill $i
echo "killed $i"
done< <(pgrep grunt)
不需要外部文件。
但是,你知道 pkill
的存在吗?
pkill grunt
pgrep, pkill - look up or signal processes based on name and other attributes
关于linux - 从 pgrep grunt 中杀死 PID 的 bash 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42696805/