fish - 为什么我的 strace 命令不适用于鱼?
问题描述
我正在尝试启动一个可以使用 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
推荐阅读
- android - 保存“lib”文件夹的位置
- c - 为什么这个用于选择排序的 C 程序给出错误的输出?
- java - 使用 URL 参数使用 Spring Boot 搜索 postgres 数据库
- c# - 一种在 2 个数组之间查找公共整数的方法
- ios - SwiftUI ScrollView:查找当前在屏幕中心可见的子视图。子视图在 ScrollView 中的位置。偏好键。滚动视图代理
- html - 调整窗口大小时如何阻止 url() 图像被裁剪?
- python - 如何在熊猫中找到最后一个数值?
- java - Camel如何配置Restlet端点来绑定每个地址
- stata - 当权重变量同时考虑基于样本和基于人口的校正时,Stata 中的权重?
- python - 使用具有 dictionary.items() 的并发期货来遍历键、值