Bun Shell は、Bun に組み込まれたクロスプラットフォームな bash ライクなシェルです。
JavaScript と TypeScript でシェルコマンドを実行するシンプルな方法を提供します。始めるには、bun パッケージから $ 関数をインポートして、シェルコマンドを実行します。
ts
import { $ } from "bun";
await $`echo Hello, world!`; // => "Hello, world!"$ 関数は、コマンドを実行し、コマンドの出力で解決される Promise を返すタグ付きテンプレートリテラルです。
ts
import { $ } from "bun";
const output = await $`ls -l`.text();
console.log(output);出力の各行を配列として取得するには、lines メソッドを使用します。
ts
import { $ } from "bun";
for await (const line of $`ls -l`.lines()) {
console.log(line);
}完全なドキュメントについては、ドキュメント > API > Shell を参照してください。