mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
Add a couple guides
This commit is contained in:
36
docs/guides/runtime/shell.md
Normal file
36
docs/guides/runtime/shell.md
Normal 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.
|
||||
15
docs/guides/util/which-path-to-executable-bin.md
Normal file
15
docs/guides/util/which-path-to-executable-bin.md
Normal 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.
|
||||
Reference in New Issue
Block a user