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 fileTake it
1234567891011121314151617181920212223242526272829303132333435363738394041<picture> <source media="(prefers-color-scheme: dark)" srcset="../media/logo_dark.svg"> <img alt="execa logo" src="../media/logo.svg" width="400"></picture><br>
# 💻 Shell
## Avoiding shells
In general, [shells](https://en.wikipedia.org/wiki/Shell_(computing)) should be avoided because they are:- Not cross-platform, encouraging shell-specific syntax.- Slower, because of the additional shell interpretation.- Unsafe, potentially allowing [command injection](https://en.wikipedia.org/wiki/Code_injection#Shell_injection) (see the [escaping section](escaping.md#shells)).
In almost all cases, plain JavaScript is a better alternative to shells. The [following page](bash.md) shows how to convert Bash into JavaScript.
## Specific shell
```jsimport {execa} from 'execa';
await execa({shell: '/bin/bash'})`npm run "$TASK" && npm run test`;```
## OS-specific shell
When 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.
`sh` and `cmd.exe` syntaxes are very different. Therefore, this is usually not useful.
```jsawait execa({shell: true})`npm run build`;```
<hr>
[**Next**: 📜 Scripts](scripts.md)\[**Previous**: 💬 Escaping/quoting](escaping.md)\[**Top**: Table of contents](../readme.md#documentation)