Write JavaScript shell scripts with Bun

Click for: original source

Thanks to Bun Shell, it’s now possible to write fast scripts in JavaScript. Some time ago, Alexandre published a test of ZX, a NodeJS wrapper for Bash. This project has inspired many others. By Anthony Rimet.

Bun is a JavaScript runtime created by Jarred Summer. Launched in 2021, it aims to create an ecosystem for developing JavaScript/TypeScript applications. It is written in Zig and powered by JavaScriptCore, which considerably reduces startup times and memory usage.

The article then explains:

  • Bun Shell
  • How does it compare to other shells?

Bun Shell provides its own implementation of popular UNIX commands such as echo. Some commands are programs, while others are “builtins”. Built-in functions are already available in a programming language or a system, without the need for explicit declaration or external libraries. They provide a standardized and efficient way to perform specific tasks. For example, in Bash, echo is a builtin, while wc is a program. Bun Shell provides builtins for commons usage so that they can be executed faster. That’s why there’s a difference in performance with ZX. Bun covers more common commands, and wants to implement more in the future.

Being able to write fast scripts in JavaScript and TypeScript, while having good performance and being more readable than Bash, is nice. Nice one!

[Read More]

Tags javascript performance web-development app-development nodejs