In general, shells 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 (see the escaping section).
In almost all cases, plain JavaScript is a better alternative to shells. The following page shows how to convert Bash into JavaScript.
On Windows, a shell is often used to work around limitations of the OS. This is not needed with Execa. In particular, shell: true is not required to:
- run
.cmdand.batfiles, such asnpm.cmd - resolve a command by name using
PATHEXT - run shebang scripts
- escape file paths and arguments
A shell is only needed to use shell-specific syntax, such as pipes |, redirections >, globbing * or environment variable expansion $VAR.
import {execa} from 'execa';
await execa({shell: '/bin/bash'})`npm run "$TASK" && npm run test`;When the shell option is true, sh is used on Unix and cmd.exe is used on Windows.
sh and cmd.exe syntaxes are very different. Therefore, this is usually not useful.
await execa({shell: true})`npm run build`;Next: 📜 Scripts
Previous: 💬 Escaping/quoting
Top: Table of contents