Bun runtime adds shell script support, with a Windows version promised shortly

Bun runtime adds shell script support, with a Windows version promised shortly

The Bun JavaScript runtime has added experimental support for shell scripts, with a post that implies this will particularly help Windows developers – although Bun does not yet support Windows, a release is said to be coming soon.

The Bun Shell enables shell scripts to be executed by bun. The main advantage is that the same script will run cross-platform. Bun creator Jarred Sumner explained that  “macOS (zsh), Linux (bash), and Windows (cmd) all have slightly different shells with different syntaxes and different commands. The commands available on each platform are different, and even the same command can have different flags and behaviors.”

Sumner gives as an example that the rimraf command is installed over 60 millions times per week according to statistics from npm (Node Package Manager). This is described as the “the UNIX command rm -rf for node” and is useful in cleanup scripts.

The Bun shell is a “new experimental embedded language and interpreter in Bun” which enables shell scripts to be written in JavaScript and TypeScript. It includes support for many popular commands and features include piping, environment variables, glob patterns, and more. It is designed as a drop-in replacement for simple shell scripts.

This first release does have notable gaps. The list of “not implemented yet” commands include mkdir, cp and cat, while mv is described as “partially implemented.”

According to Sumner, Bun Shell will work on “Windows, macOS and Linux;” but there is a problem when it comes to Windows. The docs (for Bun itself) state that “Bun provides a limited, experimental native build for Windows” and recommend that developers use the Windows subsystem for Linux (WSL) instead. The Windows build has many debugging assertions which slow it down.

Bun uses JavaScript Core, as used in the Apple-sponsored WebKit project, but there is no Safari web browser for Windows and WebKit’s Windows support is moribund. The Bun roadmap also refers to issues with Windows syscalls and filepath handling, common causes of friction for cross-platform Windows and Unix-like application code.

That said, the release notes for the Bun 1.0.25 state that “Windows is coming soon – 10 days away.” Presuming it is delivered, a stable Windows build will help Bun adoption as well as making sense of the new shell script feature.