Skip to content
Myr

shell.md

This file

Path

docs/shell.md

40 lines · 1.3 KiB · Markdown

Last changed by

Improve documentation of the "Avoiding shells" section (#998)ehmickybefore adoption24e49fe

History of this file

Take it

Add user guides (#989)ehmickybefore adoptionbe91ecf

lines 1–15why, one step back
1<picture>
2 <source media="(prefers-color-scheme: dark)" srcset="../media/logo_dark.svg">3 <img alt="execa logo" src="../media/logo.svg" width="400">4</picture>5<br>67# 💻 Shell89## Avoiding shells1011In general, [shells](https://en.wikipedia.org/wiki/Shell_(computing)) should be avoided because they are:12- Not cross-platform, encouraging shell-specific syntax.13- Slower, because of the additional shell interpretation.14- Unsafe, potentially allowing [command injection](https://en.wikipedia.org/wiki/Code_injection#Shell_injection) (see the [escaping section](escaping.md#shells)).15

Improve documentation of the "Avoiding shells" section (#998)ehmickybefore adoption24e49fe

lines 16–17why, one step back
16In almost all cases, plain JavaScript is a better alternative to shells. The [following page](bash.md) shows how to convert Bash into JavaScript.
17

Add user guides (#989)ehmickybefore adoptionbe91ecf

lines 18–27why, one step back
18## Specific shell
1920```js21import {execa} from 'execa';2223await execa({shell: '/bin/bash'})`npm run "$TASK" && npm run test`;24```2526## OS-specific shell27

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 28why, one step back
28When the [`shell`](api.md#optionsshell) option is `true`, `sh` is used on Unix and [`cmd.exe`](https://en.wikipedia.org/wiki/Cmd.exe) is used on Windows.

Add user guides (#989)ehmickybefore adoptionbe91ecf

lines 29–40why, one step back
29
30`sh` and `cmd.exe` syntaxes are very different. Therefore, this is usually not useful.3132```js33await execa({shell: true})`npm run build`;34```3536<hr>3738[**Next**: 📜 Scripts](scripts.md)\39[**Previous**: 💬 Escaping/quoting](escaping.md)\40[**Top**: Table of contents](../readme.md#documentation)