首页 > 解决方案 > 为什么我的 strace 命令不适用于鱼?

问题描述

我正在尝试启动一个可以使用 Bash 但不能使用 Fish 启动的命令:

$ sudo strace -f -s3000 -p $(pgrep -f teams -d " -p ") -o /tmp/debug.log
strace: Process 49774 attached with 32 threads
strace: Process 49778 attached
strace: Process 49780 attached
strace: Process 49817 attached with 10 threads
strace: Process 49824 attached with 6 threads
strace: Process 49848 attached with 13 threads
strace: Process 55055 attached with 6 threads
strace: Process 56914 attached with 17 threads
strace: Process 56965 attached with 44 threads
strace: Process 57041 attached with 10 threads
$ sudo strace -f -s3000 -p (pgrep -f teams -d " -p ") -o /tmp/debug.log
strace: Invalid process id: '-p'

此 strace 用于跟踪 Teams 的所有进程,这里仅是 pgrep 命令(仅供参考):

$ pgrep -f teams -d " -p "
49774 -p 49778 -p 49780 -p 49817 -p 49824 -p 49848 -p 55055 -p 56914 -p 56965 -p 57041

任何的想法 ?

标签: fish

解决方案


与 bash 不同,fish 仅在换行符上拆分命令替换,而不是空格或制表符或其他任何内容。

这意味着当您作为一个参数9774 -p 49778 -p 49780传递给时,您希望它是五个 - , , , , 。strace9774-p49778-p49780

解决方案是将其明确拆分为string split

sudo strace -f -s3000 -p (pgrep -f teams -d " -p " | string split " ") -o /tmp/debug.log

推荐阅读