Backend2025년 12월 28일1분 읽기

Bun Shell — 셸 스크립트를 TypeScript로

YS
YoungSam
조회 877

Bun Shell

Bun의 $ 태그드 템플릿으로 셸 명령을 안전하게 실행합니다.

import { $ } from "bun";

// 기본 실행
await $`echo Hello, World!`;

// 변수 안전 주입 (자동 이스케이프)
const name = "my project";
await $`mkdir -p ${name} && cd ${name}`;

// 파이프
const files = await $`ls -la | grep ".ts" | wc -l`.text();

// 조건부 실행
const result = await $`git status`.nothrow();
if (result.exitCode !== 0) {
  console.log("Not a git repo");
}

장점

  • TypeScript 타입 안전성
  • 자동 변수 이스케이프
  • 크로스 플랫폼 호환
BunShellTypeScript

댓글 0

아직 댓글이 없습니다.