Skip to content
Myr

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

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by GitHub · parent 7b044bb · Browse files · 1 file+168 added−168 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+168 added−168 removed

  • other:+168 added−168 removed

1 file+168 added−168 removed

modified:docs/scripts.md+168 added-168 removed
143 unmodified lines
144 --example-flag-one145 --example-flag-two`146```147148### Subcommands148### Concatenation149150```sh151# Bash152echo "$(echo example)"152tmpDir="/tmp"153mkdir "$tmpDir/filename"154```155156```js157// zx157const example = await $`echo example`;158await $`echo ${example}`;158const tmpDir = '/tmp'159await $`mkdir ${tmpDir}/filename`;160```161162```js163// Execa163const example = await $`echo example`;164await $`echo ${example}`;164const tmpDir = '/tmp'165await $`mkdir ${tmpDir}/filename`;166```167167### Concatenation168### Variable substitution169170```sh171# Bash171tmpDir="/tmp"172mkdir "$tmpDir/filename"172echo $LANG173```174175```js176// zx177const tmpDir = '/tmp'178await $`mkdir ${tmpDir}/filename`;177await $`echo $LANG`;178```179180```js181// Execa183const tmpDir = '/tmp'184await $`mkdir ${tmpDir}/filename`;182await $`echo ${process.env.LANG}`;183```184187### Parallel commands185### Escaping186187```sh188# Bash191echo one &192echo two &189echo 'one two'190```191192```js193// zx197await Promise.all([$`echo one`, $`echo two`]);194await $`echo ${'one two'}`;195```196197```js198// Execa202await Promise.all([$`echo one`, $`echo two`]);199await $`echo ${'one two'}`;200```201205### Serial commands202### Escaping multiple arguments203204```sh205# Bash209echo one && echo two206echo 'one two' '$'207```208209```js210// zx214await $`echo one && echo two`;211await $`echo ${['one two', '$']}`;212```213214```js215// Execa219await $`echo one`;220await $`echo two`;216await $`echo ${['one two', '$']}`;217```218223### Local binaries219### Subcommands220221```sh222# Bash227npx tsc --version223echo "$(echo example)"224```225226```js227// zx232await $`npx tsc --version`;228const example = await $`echo example`;229await $`echo ${example}`;230```231232```js233// Execa237await $`tsc --version`;234const example = await $`echo example`;235await $`echo ${example}`;236```237240### Builtin utilities238### Serial commands239240```sh241# Bash242echo one && echo two243```244245```js246// zx244const content = await stdin();247await $`echo one && echo two`;248```249250```js251// Execa249import getStdin from 'get-stdin';252await $`echo one`;253await $`echo two`;254```255251const content = await getStdin();256### Parallel commands257258```sh259# Bash260echo one &261echo two &262```263254### Variable substitution264```js265// zx266await Promise.all([$`echo one`, $`echo two`]);267```268269```js270// Execa271await Promise.all([$`echo one`, $`echo two`]);272```273274### Global/shared options275276```sh277# Bash258echo $LANG278options="timeout 5"279$options echo one280$options echo two281$options echo three282```283284```js285// zx263await $`echo $LANG`;286const timeout = '5s';287await $`echo one`.timeout(timeout);288await $`echo two`.timeout(timeout);289await $`echo three`.timeout(timeout);290```291292```js293// Execa268await $`echo ${process.env.LANG}`;294import {$ as $_} from 'execa';295296const $ = $_({timeout: 5000});297298await $`echo one`;299await $`echo two`;300await $`echo three`;301```302303### Environment variables304
13 unmodified lines
318// Execa319await $({env: {EXAMPLE: '1'}})`example_command`;320```321290### Escaping322### Local binaries323324```sh325# Bash294echo 'one two'326npx tsc --version327```328329```js330// zx299await $`echo ${'one two'}`;331await $`npx tsc --version`;332```333334```js335// Execa304await $`echo ${'one two'}`;336await $`tsc --version`;337```338307### Escaping multiple arguments339### Builtin utilities340341```js342// zx343const content = await stdin();344```345346```js347// Execa348import getStdin from 'get-stdin';349350const content = await getStdin();351```352353### Printing to stdout354355```sh356# Bash311echo 'one two' '$'357echo example358```359360```js361// zx316await $`echo ${['one two', '$']}`;362echo`example`;363```364365```js366// Execa321await $`echo ${['one two', '$']}`;367console.log('example');368```369324### Current filename370### Silent stderr371372```sh373# Bash328echo "$(basename "$0")"374echo example 2> /dev/null375```376377```js378// zx333await $`echo ${__filename}`;379await $`echo example`.stdio('inherit', 'pipe', 'ignore');380```381382```js337// Execa338import {fileURLToPath} from 'node:url';339import path from 'node:path';340341const __filename = path.basename(fileURLToPath(import.meta.url));342343await $`echo ${__filename}`;383// Execa does not print stdout/stderr by default384await $`echo example`;385```386387### Verbose mode388
25 unmodified lines
414```415NODE_DEBUG=execa node file.js416```417377### Current directory418### Piping stdout to another command419420```sh421# Bash381cd project422echo npm run build | sort | head -n2423```424425```js426// zx386cd('project');387388// or:389$.cwd = 'project';427await $`npm run build | sort | head -n2`;428```429430```js431// Execa394const $$ = $({cwd: 'project'});432await $`npm run build`433 .pipe`sort`434 .pipe`head -n2`;435```436397### Multiple current directories437### Piping stdout and stderr to another command438439```sh440# Bash401pushd project402pwd403popd404pwd441echo example |& cat442```443444```js445// zx409within(async () => {410 cd('project');411 await $`pwd`;412});413414await $`pwd`;446const echo = $`echo example`;447const cat = $`cat`;448echo.pipe(cat)449echo.stderr.pipe(cat.stdin);450await Promise.all([echo, cat]);451```452453```js454// Execa419await $({cwd: 'project'})`pwd`;420await $`pwd`;455await $({all: true})`echo example`456 .pipe({from: 'all'})`cat`;457```458423### Exit codes459### Piping stdout to a file460461```sh462# Bash427false428echo $?463echo example > file.txt464```465466```js467// zx433const {exitCode} = await $`false`.nothrow();434echo`${exitCode}`;468await $`echo example`.pipe(fs.createWriteStream('file.txt'));469```470471```js472// Execa439const {exitCode} = await $({reject: false})`false`;440console.log(exitCode);473await $({stdout: {file: 'file.txt'}})`echo example`;474```475443### Timeouts476### Piping stdin from a file477478```sh479# Bash447timeout 5 echo example480echo example < file.txt481```482483```js484// zx452await $`echo example`.timeout('5s');485const cat = $`cat`486fs.createReadStream('file.txt').pipe(cat.stdin)487await cat488```489490```js491// Execa457await $({timeout: 5000})`echo example`;492await $({inputFile: 'file.txt'})`cat`493```494460### PID461462```sh463# Bash464echo example &465echo $!466```467468```js469// zx does not return `childProcess.pid`470```471472```js473// Execa474const {pid} = $`echo example`;475```476495### Errors496497```sh498# Bash communicates errors only through the exit code and stderr
70 unmodified lines
569// isTerminated: false570// }571```572555### Global/shared options573### Exit codes574575```sh576# Bash559options="timeout 5"560$options echo one561$options echo two562$options echo three577false578echo $?579```580581```js582// zx567const timeout = '5s';568await $`echo one`.timeout(timeout);569await $`echo two`.timeout(timeout);570await $`echo three`.timeout(timeout);583const {exitCode} = await $`false`.nothrow();584echo`${exitCode}`;585```586587```js588// Execa575import {$ as $_} from 'execa';576577const $ = $_({timeout: 5000});578579await $`echo one`;580await $`echo two`;581await $`echo three`;589const {exitCode} = await $({reject: false})`false`;590console.log(exitCode);591```592584### Background processes593### Timeouts594595```sh596# Bash588echo one &597timeout 5 echo example598```599600```js592// zx does not allow setting the `detached` option601// zx602await $`echo example`.timeout('5s');603```604605```js606// Execa597await $({detached: true})`echo one`;607await $({timeout: 5000})`echo example`;608```609600### Printing to stdout610### Current filename611612```sh613# Bash604echo example614echo "$(basename "$0")"615```616617```js618// zx609echo`example`;619await $`echo ${__filename}`;620```621622```js623// Execa614console.log('example');615```624import {fileURLToPath} from 'node:url';625import path from 'node:path';626617### Piping stdout to another command627const __filename = path.basename(fileURLToPath(import.meta.url));628619```sh620# Bash621echo npm run build | sort | head -n2629await $`echo ${__filename}`;630```631624```js625// zx626await $`npm run build | sort | head -n2`;627```632### Current directory633629```js630// Execa631await $`npm run build`632 .pipe`sort`633 .pipe`head -n2`;634```635636### Piping stdout and stderr to another command637634```sh635# Bash640echo example |& cat636cd project637```638639```js640// zx645const echo = $`echo example`;646const cat = $`cat`;647echo.pipe(cat)648echo.stderr.pipe(cat.stdin);649await Promise.all([echo, cat]);641cd('project');642643// or:644$.cwd = 'project';645```646647```js648// Execa654await $({all: true})`echo example`655 .pipe({from: 'all'})`cat`;649const $$ = $({cwd: 'project'});650```651658### Piping stdout to a file652### Multiple current directories653654```sh655# Bash662echo example > file.txt656pushd project657pwd658popd659pwd660```661662```js663// zx667await $`echo example`.pipe(fs.createWriteStream('file.txt'));664within(async () => {665 cd('project');666 await $`pwd`;667});668669await $`pwd`;670```671672```js673// Execa672await $({stdout: {file: 'file.txt'}})`echo example`;674await $({cwd: 'project'})`pwd`;675await $`pwd`;676```677675### Piping stdin from a file678### Background processes679680```sh681# Bash679echo example < file.txt682echo one &683```684685```js683// zx684const cat = $`cat`685fs.createReadStream('file.txt').pipe(cat.stdin)686await cat686// zx does not allow setting the `detached` option687```688689```js690// Execa691await $({inputFile: 'file.txt'})`cat`691await $({detached: true})`echo one`;692```693694### Silent stderr694### PID695696```sh697# Bash698echo example 2> /dev/null698echo example &699echo $!700```701702```js702// zx703await $`echo example`.stdio('inherit', 'pipe', 'ignore');703// zx does not return `childProcess.pid`704```705706```js707// Execa does not forward stdout/stderr by default708await $`echo example`;707// Execa708const {pid} = $`echo example`;709```