I'm trying to launch a command that I'm able to launch with Bash but not with 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'
This strace is to follow all the processes of Teams, here is the pgrep command only (for info) :
$ pgrep -f teams -d " -p "
49774 -p 49778 -p 49780 -p 49817 -p 49824 -p 49848 -p 55055 -p 56914 -p 56965 -p 57041
Any idea ?
Unlike bash, fish splits command substitutions on newlines only, not spaces or tabs or anything else.
This means when your 9774 -p 49778 -p 49780
is passed to strace
as one argument, where you want it to be five - 9774
, -p
, 49778
, -p
, 49780
.
The solution is to just split it explicitly with string split
:
sudo strace -f -s3000 -p (pgrep -f teams -d " -p " | string split " ") -o /tmp/debug.log