gpt4 book ai didi

linux - 如何在shell中逐行获取 `ps`的输出

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:04:29 25 4
gpt4 key购买 nike

我想在 shell 中通过 ps 列出一个进程及其信息。这是我的脚本:

#!/bin/sh

for line in `ps aux| grep test.py`
do
echo $line
done

但是输出是:

hey
13241
0.0
0.3
48388
13528
pts/18
S+
18:50
0:00
python
test.py
hey
13370
0.0
0.0
14504
1016
pts/21
S+
19:00
0:00
grep
test.py

它将线路分成许多部分,但我希望我可以在终端中像命令一样获得名称为 test.py 的进程的一行信息:

hey   13241  0.0  0.3  48388 13528 pts/18   S+   18:50   0:00 python test.py
hey 13446 0.0 0.0 14504 976 pts/21 S+ 19:08 0:00 grep --color=auto test.py

如何解决

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com