Quotes in child command not supported
What reproduces the bug? Provide code if possible.
I tried to use the -c option with a command including quotes to escape a string with spaces, like this:
sudo bpftrace -c "echo 'test test'" -e ...This setup causes echo to print: 'test test' which is unexpected. I would expect the output to be test test, without the surrounding quotes.
I tracked the reason for this down to the function utils::create_child where the child command string is split at every space, even when surrounded by quotes.
I would expect the -c option to respect ' and " quotes.
I only tested with version 0.23.5, but I am fairly sure this issue still exists in the current version, by looking at the source.
This issue should be easily solved by writing a new split_string function which only splits if the delimiter isn't surrounded by quotes.
bpftrace --info output
System OS: Linux 6.15.5-200.fc42.x86_64 #1 SMP PREEMPT_DYNAMIC Sun Jul 6 09:16:17 UTC 2025 Arch: x86_64
Build version: v0.23.5 LLVM: 20.1.6 bfd: yes liblldb (DWARF support): yes libsystemd (systemd notify support): no
Kernel helpers
probe_read: yes probe_read_str: yes
probe_read_user: yes probe_read_user_str: yes
probe_read_kernel: yes probe_read_kernel_str: yes
get_current_cgroup_id: yes send_signal: yes
override_return: no get_boot_ns: yes
dpath: yes skboutput: yes
get_tai_ns: yes get_func_ip: yes
jiffies64: yes for_each_map_elem: yes
get_ns_current_pid_tgid: yes lookup_percpu_elem: yes
Kernel features
Instruction limit: 1000000 btf: yes
module btf: yes Kernel DWARF: no
map batch: yes uprobe refcount: yes
Map types
hash: yes array: yes
percpu array: yes stack_trace: yes
perf_event_array: yes ringbuf: yes
Probe types
kprobe: yes tracepoint: yes
perf_event: yes fentry: yes
kprobe_multi: yes uprobe_multi: yes
iter: yes
Source: bpftrace/bpftrace