Skip to content
Myr

scripts.md

This file

Path

docs/scripts.md

709 lines · 11.3 KiB · Markdown

Last changed by

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

History of this file

Take it

The walk stopped after 200 commits: lines older than db2ad9a point at it.

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 1–8why, one step back
1# Node.js scripts
23With Execa, you can write scripts with Node.js instead of a shell language. It is [secure](#escaping), [performant](#performance), [simple](#simplicity) and [cross-platform](#shell).45```js6import {$} from 'execa';78const {stdout: name} = await $`cat package.json`

`.pipe()` shortcut for `$` (#840)ehmickybefore adoption316f562

line 9why, one step back
9 .pipe`grep name`;

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 10–123why, one step back
10console.log(name);
1112const branch = await $`git branch --show-current`;13await $`dep deploy --branch=${branch}`;1415await Promise.all([16 $`sleep 1`,17 $`sleep 2`,18 $`sleep 3`,19]);2021const dirName = 'foo bar';22await $`mkdir /tmp/${dirName}`;23```2425## Summary2627This file describes the differences between Bash, Execa, and [zx](https://github.com/google/zx) (which inspired this feature).2829### Flexibility3031Unlike shell languages like Bash, libraries like Execa and zx enable you to write scripts with a more featureful programming language (JavaScript). This allows complex logic (such as [parallel execution](#parallel-commands)) to be expressed easily. This also lets you use [any Node.js package](#builtin-utilities).3233### Shell3435The main difference between Execa and zx is that Execa does not require any shell. Shell-specific keywords and features are [written in JavaScript](#variable-substitution) instead.3637This is more cross-platform. For example, your code works the same on Windows machines without Bash installed.3839Also, there is no shell syntax to remember: everything is just plain JavaScript.4041If you really need a shell though, the [`shell` option](../readme.md#shell) can be used.4243### Simplicity4445Execa's scripting API mostly consists of only two methods: [`` $`command` ``](../readme.md#command) and [`$(options)`](../readme.md#options).4647[No special binary](#main-binary) is recommended, no [global variable](#global-variables) is injected: scripts are regular Node.js files.4849Execa is a thin wrapper around the core Node.js [`child_process` module](https://nodejs.org/api/child_process.html). Unlike zx, it lets you use [any of its native features](#background-processes): [`pid`](#pid), [IPC](https://nodejs.org/api/child_process.html#subprocesssendmessage-sendhandle-options-callback), [`unref()`](https://nodejs.org/api/child_process.html#subprocessunref), [`detached`](https://nodejs.org/api/child_process.html#child_processspawncommand-args-options), [`uid`](https://nodejs.org/api/child_process.html#child_processspawncommand-args-options), [`gid`](https://nodejs.org/api/child_process.html#child_processspawncommand-args-options), [`signal`](https://nodejs.org/api/child_process.html#child_processspawncommand-args-options), etc.5051### Modularity5253zx includes many builtin utilities: `fetch()`, `question()`, `sleep()`, `stdin()`, `retry()`, `spinner()`, `chalk`, `fs-extra`, `os`, `path`, `globby`, `yaml`, `minimist`, `which`, Markdown scripts, remote scripts.5455Execa does not include [any utility](#builtin-utilities): it focuses on being small and modular instead. Any Node.js package can be used in your scripts.5657### Performance5859Spawning a shell for every command comes at a performance cost, which Execa avoids.6061Also, [local binaries](#local-binaries) can be directly executed without using `npx`.6263### Debugging6465Child processes can be hard to debug, which is why Execa includes a [`verbose` option](#verbose-mode).6667Also, Execa's error messages and [properties](#errors) are very detailed to make it clear to determine why a process failed.6869Finally, unlike Bash and zx, which are stateful (options, current directory, etc.), Execa is [purely functional](#current-directory), which also helps with debugging.7071## Details7273### Main binary7475```sh76# Bash77bash file.sh78```7980```js81// zx82zx file.js8384// or a shebang can be used:85// #!/usr/bin/env zx86```8788```js89// Execa scripts are just regular Node.js files90node file.js91```9293### Global variables9495```js96// zx97await $`echo example`;98```99100```js101// Execa102import {$} from 'execa';103104await $`echo example`;105```106107### Command execution108109```sh110# Bash111echo example112```113114```js115// zx116await $`echo example`;117```118119```js120// Execa121await $`echo example`;122```123

Allow newlines in `$` (#843)ehmickybefore adoption1315486

lines 124–147why, one step back
124### Multiline commands
125126```sh127# Bash128npm run build \129 --example-flag-one \130 --example-flag-two131```132133```js134// zx135await $`npm run build ${[136 '--example-flag-one',137 '--example-flag-two',138]}`;139```140141```js142// Execa143await $`npm run build144 --example-flag-one145 --example-flag-two`146```147

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 148why, one step back
148### Concatenation

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 149–151why, one step back
149
150```sh151# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 152–153why, one step back
152tmpDir="/tmp"
153mkdir "$tmpDir/filename"

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 154–157why, one step back
154```
155156```js157// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 158–159why, one step back
158const tmpDir = '/tmp'
159await $`mkdir ${tmpDir}/filename`;

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 160–163why, one step back
160```
161162```js163// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 164–165why, one step back
164const tmpDir = '/tmp'
165await $`mkdir ${tmpDir}/filename`;

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 166–167why, one step back
166```
167

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 168why, one step back
168### Variable substitution

Fix argument concatenation with `$` (#553)ehmickybefore adoption07585d0

lines 169–171why, one step back
169
170```sh171# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 172why, one step back
172echo $LANG

Fix argument concatenation with `$` (#553)ehmickybefore adoption07585d0

lines 173–176why, one step back
173```
174175```js176// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 177why, one step back
177await $`echo $LANG`;

Fix argument concatenation with `$` (#553)ehmickybefore adoption07585d0

lines 178–181why, one step back
178```
179180```js181// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 182why, one step back
182await $`echo ${process.env.LANG}`;

Fix argument concatenation with `$` (#553)ehmickybefore adoption07585d0

lines 183–184why, one step back
183```
184

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 185why, one step back
185### Escaping

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 186–188why, one step back
186
187```sh188# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 189why, one step back
189echo 'one two'

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 190–193why, one step back
190```
191192```js193// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 194why, one step back
194await $`echo ${'one two'}`;

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 195–198why, one step back
195```
196197```js198// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 199why, one step back
199await $`echo ${'one two'}`;

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 200–201why, one step back
200```
201

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 202why, one step back
202### Escaping multiple arguments

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 203–205why, one step back
203
204```sh205# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 206why, one step back
206echo 'one two' '$'

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 207–210why, one step back
207```
208209```js210// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 211why, one step back
211await $`echo ${['one two', '$']}`;

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 212–215why, one step back
212```
213214```js215// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 216why, one step back
216await $`echo ${['one two', '$']}`;

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 217–218why, one step back
217```
218

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 219why, one step back
219### Subcommands

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 220–222why, one step back
220
221```sh222# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 223why, one step back
223echo "$(echo example)"

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 224–227why, one step back
224```
225226```js227// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 228–229why, one step back
228const example = await $`echo example`;
229await $`echo ${example}`;

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 230–233why, one step back
230```
231232```js233// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 234–235why, one step back
234const example = await $`echo example`;
235await $`echo ${example}`;

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 236–237why, one step back
236```
237

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 238why, one step back
238### Serial commands

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

line 239why, one step back
239

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 240–244why, one step back
240```sh
241# Bash242echo one && echo two243```244

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 245–246why, one step back
245```js
246// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 247why, one step back
247await $`echo one && echo two`;

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 248–251why, one step back
248```
249250```js251// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 252–254why, one step back
252await $`echo one`;
253await $`echo two`;254```

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

line 255why, one step back
255

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 256–261why, one step back
256### Parallel commands
257258```sh259# Bash260echo one &261echo two &

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 262–263why, one step back
262```
263

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 264–267why, one step back
264```js
265// zx266await Promise.all([$`echo one`, $`echo two`]);267```

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

line 268why, one step back
268

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 269–275why, one step back
269```js
270// Execa271await Promise.all([$`echo one`, $`echo two`]);272```273274### Global/shared options275

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 276–277why, one step back
276```sh
277# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 278–281why, one step back
278options="timeout 5"
279$options echo one280$options echo two281$options echo three

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 282–285why, one step back
282```
283284```js285// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 286–289why, one step back
286const timeout = '5s';
287await $`echo one`.timeout(timeout);288await $`echo two`.timeout(timeout);289await $`echo three`.timeout(timeout);

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 290–293why, one step back
290```
291292```js293// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 294–300why, one step back
294import {$ as $_} from 'execa';
295296const $ = $_({timeout: 5000});297298await $`echo one`;299await $`echo two`;300await $`echo three`;

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 301–321why, one step back
301```
302303### Environment variables304305```sh306# Bash307EXAMPLE=1 example_command308```309310```js311// zx312$.env.EXAMPLE = '1';313await $`example_command`;314delete $.env.EXAMPLE;315```316317```js318// Execa319await $({env: {EXAMPLE: '1'}})`example_command`;320```321

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 322why, one step back
322### Local binaries

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 323–325why, one step back
323
324```sh325# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 326why, one step back
326npx tsc --version

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 327–330why, one step back
327```
328329```js330// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 331why, one step back
331await $`npx tsc --version`;

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 332–335why, one step back
332```
333334```js335// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 336why, one step back
336await $`tsc --version`;

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 337–338why, one step back
337```
338

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 339why, one step back
339### Builtin utilities

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

line 340why, one step back
340

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 341–354why, one step back
341```js
342// zx343const content = await stdin();344```345346```js347// Execa348import getStdin from 'get-stdin';349350const content = await getStdin();351```352353### Printing to stdout354

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 355–356why, one step back
355```sh
356# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 357why, one step back
357echo example

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 358–361why, one step back
358```
359360```js361// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 362why, one step back
362echo`example`;

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 363–366why, one step back
363```
364365```js366// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 367why, one step back
367console.log('example');

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 368–369why, one step back
368```
369

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 370why, one step back
370### Silent stderr

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 371–373why, one step back
371
372```sh373# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 374why, one step back
374echo example 2> /dev/null

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 375–378why, one step back
375```
376377```js378// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 379why, one step back
379await $`echo example`.stdio('inherit', 'pipe', 'ignore');

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 380–382why, one step back
380```
381382```js

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 383–384why, one step back
383// Execa does not print stdout/stderr by default
384await $`echo example`;

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 385–404why, one step back
385```
386387### Verbose mode388389```sh390# Bash391set -v392echo example393```394395```js396// zx >=8397await $`echo example`.verbose();398399// or:400$.verbose = true;401```402403```js404// Execa

Improve documentation of global script options (#870)ehmickybefore adoption146fa07

lines 405–409why, one step back
405import {$ as $_} from 'execa';
406407const $ = $_({verbose: true});408409await $`echo example`;

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 410–417why, one step back
410```
411412Or:413414```415NODE_DEBUG=execa node file.js416```417

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 418why, one step back
418### Piping stdout to another command

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 419–421why, one step back
419
420```sh421# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 422why, one step back
422echo npm run build | sort | head -n2

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 423–426why, one step back
423```
424425```js426// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 427why, one step back
427await $`npm run build | sort | head -n2`;

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 428–431why, one step back
428```
429430```js431// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 432–434why, one step back
432await $`npm run build`
433 .pipe`sort`434 .pipe`head -n2`;

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 435–436why, one step back
435```
436

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 437why, one step back
437### Piping stdout and stderr to another command

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 438–440why, one step back
438
439```sh440# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 441why, one step back
441echo example |& cat

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 442–445why, one step back
442```
443444```js445// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 446–450why, one step back
446const echo = $`echo example`;
447const cat = $`cat`;448echo.pipe(cat)449echo.stderr.pipe(cat.stdin);450await Promise.all([echo, cat]);

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 451–454why, one step back
451```
452453```js454// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 455–456why, one step back
455await $({all: true})`echo example`
456 .pipe({from: 'all'})`cat`;

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 457–458why, one step back
457```
458

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 459why, one step back
459### Piping stdout to a file

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 460–462why, one step back
460
461```sh462# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 463why, one step back
463echo example > file.txt

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 464–467why, one step back
464```
465466```js467// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 468why, one step back
468await $`echo example`.pipe(fs.createWriteStream('file.txt'));

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 469–472why, one step back
469```
470471```js472// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 473why, one step back
473await $({stdout: {file: 'file.txt'}})`echo example`;

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 474–475why, one step back
474```
475

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 476why, one step back
476### Piping stdin from a file

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 477–479why, one step back
477
478```sh479# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 480why, one step back
480echo example < file.txt

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 481–484why, one step back
481```
482483```js484// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 485–487why, one step back
485const cat = $`cat`
486fs.createReadStream('file.txt').pipe(cat.stdin)487await cat

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 488–491why, one step back
488```
489490```js491// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 492why, one step back
492await $({inputFile: 'file.txt'})`cat`

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 493–547why, one step back
493```
494495### Errors496497```sh498# Bash communicates errors only through the exit code and stderr499timeout 1 sleep 2500echo $?501```502503```js504// zx505const {506 stdout,507 stderr,508 exitCode,509 signal,510} = await $`sleep 2`.timeout('1s');511// file:///home/me/Desktop/node_modules/zx/build/core.js:146512// let output = new ProcessOutput(code, signal, stdout, stderr, combined, message);513// ^514// ProcessOutput [Error]:515// at file:///home/me/Desktop/example.js:2:20516// exit code: null517// signal: SIGTERM518// at ChildProcess.<anonymous> (file:///home/me/Desktop/node_modules/zx/build/core.js:146:26)519// at ChildProcess.emit (node:events:512:28)520// at maybeClose (node:internal/child_process:1098:16)521// at Socket.<anonymous> (node:internal/child_process:456:11)522// at Socket.emit (node:events:512:28)523// at Pipe.<anonymous> (node:net:316:12)524// at Pipe.callbackTrampoline (node:internal/async_hooks:130:17) {525// _code: null,526// _signal: 'SIGTERM',527// _stdout: '',528// _stderr: '',529// _combined: ''530// }531```532533```js534// Execa535const {536 stdout,537 stderr,538 exitCode,539 signal,540 signalDescription,541 originalMessage,542 shortMessage,543 command,544 escapedCommand,545 failed,546 timedOut,547 isCanceled,

Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c

line 548why, one step back
548 isTerminated,

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 549–568why, one step back
549 // and other error-related properties: code, etc.
550} = await $({timeout: 1})`sleep 2`;551// file:///home/me/code/execa/lib/kill.js:60552// reject(Object.assign(new Error('Timed out'), {timedOut: true, signal}));553// ^554// Error: Command timed out after 1 milliseconds: sleep 2555// Timed out556// at file:///home/me/Desktop/example.js:2:20557// timedOut: true,558// signal: 'SIGTERM',559// originalMessage: 'Timed out',560// shortMessage: 'Command timed out after 1 milliseconds: sleep 2\nTimed out',561// command: 'sleep 2',562// escapedCommand: 'sleep 2',563// exitCode: undefined,564// signalDescription: 'Termination',565// stdout: '',566// stderr: '',567// failed: true,568// isCanceled: false,

Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c

line 569why, one step back
569// isTerminated: false

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 570–572why, one step back
570// }
571```572

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 573why, one step back
573### Exit codes

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 574–576why, one step back
574
575```sh576# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 577–578why, one step back
577false
578echo $?

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 579–582why, one step back
579```
580581```js582// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 583–584why, one step back
583const {exitCode} = await $`false`.nothrow();
584echo`${exitCode}`;

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 585–588why, one step back
585```
586587```js588// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 589–590why, one step back
589const {exitCode} = await $({reject: false})`false`;
590console.log(exitCode);

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 591–592why, one step back
591```
592

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 593why, one step back
593### Timeouts

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 594–596why, one step back
594
595```sh596# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 597why, one step back
597timeout 5 echo example

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 598–600why, one step back
598```
599600```js

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 601–602why, one step back
601// zx
602await $`echo example`.timeout('5s');

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 603–606why, one step back
603```
604605```js606// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 607why, one step back
607await $({timeout: 5000})`echo example`;

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 608–609why, one step back
608```
609

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 610why, one step back
610### Current filename

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 611–613why, one step back
611
612```sh613# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 614why, one step back
614echo "$(basename "$0")"

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 615–618why, one step back
615```
616617```js618// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 619why, one step back
619await $`echo ${__filename}`;

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 620–623why, one step back
620```
621622```js623// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 624–625why, one step back
624import {fileURLToPath} from 'node:url';
625import path from 'node:path';

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

line 626why, one step back
626

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 627why, one step back
627const __filename = path.basename(fileURLToPath(import.meta.url));

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

line 628why, one step back
628

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 629why, one step back
629await $`echo ${__filename}`;

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 630–631why, one step back
630```
631

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 632why, one step back
632### Current directory

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 633–635why, one step back
633
634```sh635# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 636why, one step back
636cd project

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 637–640why, one step back
637```
638639```js640// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 641–644why, one step back
641cd('project');
642643// or:644$.cwd = 'project';

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 645–648why, one step back
645```
646647```js648// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 649why, one step back
649const $$ = $({cwd: 'project'});

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 650–651why, one step back
650```
651

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 652why, one step back
652### Multiple current directories

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 653–655why, one step back
653
654```sh655# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 656–659why, one step back
656pushd project
657pwd658popd659pwd

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 660–663why, one step back
660```
661662```js663// zx

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 664–669why, one step back
664within(async () => {
665 cd('project');666 await $`pwd`;667});668669await $`pwd`;

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 670–673why, one step back
670```
671672```js673// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 674–675why, one step back
674await $({cwd: 'project'})`pwd`;
675await $`pwd`;

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 676–677why, one step back
676```
677

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 678why, one step back
678### Background processes

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 679–681why, one step back
679
680```sh681# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 682why, one step back
682echo one &

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 683–685why, one step back
683```
684685```js

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 686why, one step back
686// zx does not allow setting the `detached` option

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 687–690why, one step back
687```
688689```js690// Execa

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 691why, one step back
691await $({detached: true})`echo one`;

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 692–693why, one step back
692```
693

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 694why, one step back
694### PID

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 695–697why, one step back
695
696```sh697# Bash

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 698–699why, one step back
698echo example &
699echo $!

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 700–702why, one step back
700```
701702```js

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

line 703why, one step back
703// zx does not return `childProcess.pid`

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

lines 704–706why, one step back
704```
705706```js

Reorder sections in `docs/scripts.md` (#876)ehmickybefore adoption2cd41ef

lines 707–708why, one step back
707// Execa
708const {pid} = $`echo example`;

Improve main method documentation (#545)ehmickybefore adoptiondb2ad9a

line 709why, one step back
709```