我正在尝试启动一个可以使用 Bash 启动但不能使用 Fish 启动的命令:
- 在 Bash 上,这运行良好:
$ 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
- 在 Fish 上,我尝试了相同的操作,但没有“$”,但出现错误:
$ 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
有什么想法吗?
最佳答案
与 bash 不同,fish 仅在换行符上分割命令替换,而不是空格或制表符或其他任何内容。
这意味着当您的 9774 -p 49778 -p 49780
被传递到strace
作为一个参数,您希望它是五个 - 9774
, -p
, 49778
, -p
, 49780
.
解决方案是将其显式拆分为 string split
:
sudo strace -f -s3000 -p (pgrep -f teams -d " -p " | string split " ") -o /tmp/debug.log
关于fish - 为什么我的 strace 命令不适用于 Fish?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66155978/