fish - 为什么我的 strace 命令不适用于 Fish?

标签 fish

我正在尝试启动一个可以使用 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/

相关文章:

prompt - 在 Fish Shell 中获取当前目录(没有完整路径)

terminal - fish 终端突出显示 1 个文件夹及其大部分子文件夹

bash - 切换到 zsh shell -- `ls` 结束终端选项卡

fish - `bind` 不运行用户定义函数

macos - 在 macOS 上的 Fish shell 中为命令添加超时

fish - 如何在 fish shell 历史中添加条目?

shell - 奇怪的 fish 提示

shell - 测试是否存在特定类型的文件

shell - 多行变量删除换行符 - Fish

bash - 如何在 fish 中使用 bash 函数