Master the vocabulary of Bun Shell's subprocess API, including the $`...` syntax, output capture methods, piping, and cross-platform scripting features.
0 / 5 completed
1 / 5
What does the $`...` template literal syntax do in Bun Shell?
$`...` is Bun Shell's subprocess-spawning syntax. It executes the command inside the backticks as a shell process and returns a promise resolving to the output. Example: const result = await $`ls -la`;
2 / 5
How do you capture stdout as a string in a Bun Shell command?
Capturing stdout in Bun Shell is done with .text() — e.g., const out = await $`echo hello`.text();. Other formats include .json() for JSON output and .blob() for binary data.
3 / 5
Which method chains two Bun Shell commands so the stdout of the first is the stdin of the second (piping)?
Piping in Bun Shell works by writing the pipe operator directly inside the template literal: await $`cat file.txt | grep error`. Bun interprets the | inside the template and wires processes together, matching native shell behaviour.
4 / 5
What advantage does Bun Shell offer for cross-platform scripting compared to raw child_process.exec?
Cross-platform scripting is a core Bun Shell goal: it ships its own POSIX-like shell interpreter, so commands like ls, rm, and pipes work on Windows without Git Bash or WSL. This removes the platform dependency that affects child_process.exec with system shells.
5 / 5
How can you pass a JavaScript variable safely into a Bun Shell command to avoid shell injection?
Shell injection is prevented by Bun Shell automatically escaping any JavaScript value interpolated via ${} inside the template literal. For example $`rm ${filename}` will quote filename so a value like ; rm -rf / cannot break out of the argument.