Add a couple guides

This commit is contained in:
Jarred Sumner
2024-03-02 01:24:40 -08:00
parent 309b417009
commit 3c62580529
2 changed files with 51 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
---
name: Run a Shell Command
---
Bun Shell is a cross-platform bash-like shell built in to Bun. It provides a simple way to run shell commands in JavaScript and TypeScript.
To get started, import the `$` function from the `bun` package and use it to run shell commands.
```ts#foo.ts
import { $ } from "bun";
await $`echo Hello, world!`; // => "Hello, world!"
```
The `$` function is a tagged template literal that runs the command and returns a promise that resolves with the command's output.
```ts#foo.ts
import { $ } from "bun";
const output = await $`ls -l`.text();
console.log(output);
```
To get each line of the output as an array, use the `lines` method.
```ts#foo.ts
import { $ } from "bun";
for await (const line of $`ls -l`.lines()) {
console.log(line);
}
```
---
See [Docs > API > Shell](/api/shell) for complete documentation.

View File

@@ -0,0 +1,15 @@
---
name: Get the path to an executable bin file
---
`Bun.which` is a utility function to find the absolute path of an executable file. It is similar to the `which` command in Unix-like systems.
```ts#foo.ts
Bun.which("sh"); // => "/bin/sh"
Bun.which("notfound"); // => null
Bun.which("bun"); // => "/home/user/.bun/bin/bun"
```
---
See [Docs > API > Utils](/api/utils#bun-which) for complete documentation.