Live data from Hacker News

The Bun Shell

bun.sh

11–20 of 239 posts

Re: The Bun Shell

#11
It feels like the people behind bun are trying to differentiate from node so much that they sometimes don't stop to ask why.

I'm sure there's a use-case somewhere, but if I'm using js I will just use a regex instead of reaching for grep. If I want the shell I'll use the shell.

Re: The Bun Shell

#12

For something which works across all JS runtimes (Deno, Node) and achieves basically the same, check out the popular JS library Execa[1]. Works like a charm! Another alternative is the ZX shell[2] JS library. Tho haven't tested it. [1]: https://github.com/sindresorhus/execa [2]: https://github.com/google/zx

I’m using zx and the API seems very similar to what is described in the post.

Which bun also acknowledges here:

https://github.com/oven-sh/bun/blob/main/docs/runtime/shell....

I suppose one significant difference is that bun reimplements shell built-ins. I believe that zx simply executes bash or powershell and fails if neither is available.

Re: The Bun Shell

#13
> We've implemented many common commands and features like globbing, environment variables, redirection, piping, and more.

Of course on paper that sounds fine. However, something that is missing from here is some assurances of how compatible it actually is with existing shells and coreutils implementations. Is it aiming to be POSIX-compliant/compatible with Bourne shell? I am going to assume that not all GNU extensions are available; probably something like mkdir -p is, but I'd be surprised if GNU find with all of its odds and ends are there. This might be good enough, but this is a bit light on the details I think. What happens when the system has GNU coreutils? If more builtin commands are added in the future, will they magically change into the Bun implementation instead of the GNU coreutils implementation unexpectedly? I'm sure it is/will be documented...

Also, it's probably obvious but you likely would not want to surprise-replace a Bourne-compatible shell like ZShell with this in most contexts. This only makes sense in the JS ecosystem because there is already a location where you have to write commands that are going to be compatible with all of these shells anyways, so just standardizing on some more-useful subset of Bourne-compatible shell is mostly an upgrade, since that'll be a lot more uniform and your new subset is still going to be nearly 100% compatible with anything that worked across most platforms before, except it will work across all of the platforms as-intended. (And having the nifty ability to use it inside of JS scripts in an ergonomic way is a plus too, although plenty of JS libraries do similar things, so that's not too new.)

Re: The Bun Shell

#15

It feels like the people behind bun are trying to differentiate from node so much that they sometimes don't stop to ask why. I'm sure there's a use-case somewhere, but if I'm using js I will just use a regex instead of reaching for grep. If I want the shell I'll use the shell.

The most common usecase is probably “I have `rm` in the scripts section of package.json, and it doesn’t work on windows.”

Re: The Bun Shell

#17

Can somebody explain why they’re attributing ZSH to macOS? It’s clearly cross platform

It would be equally appropriate/wrong to say that mksh, the MirBSD Korn shell, is Android's system shell.

The manual page for mksh also mentions Android in the introduction for those who do not understand the role.

Re: The Bun Shell

#20
post #8
post #7

I didn't know, but apparently you can execute a function in JS without parentheses using upticks (`), e.g: functionName`param` and whatever is inside of the upticks get sent to the function as an array. It's also what Bun is doing with it's $ (dollar sign) function for executing shell commands. There's so much weird syntax magic in JS.

These are called "tagged templates": https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

Tagged templates are really cool. They are a reasonably simple extension of template strings, which allow constructing strings very easily by allowing arbitrary code to be put inside a ${} block inside of template strings (ones that begin and end with backticks ` instead of single or double quotes).

So if you think about it template strings are like a tagged template who's function just calls .toString() and concatenates each argument it is given. There are some really nice safe sql libraries that use this for constructing queries. They are useful basically anywhere you might want string interpolation and a bit of type safety, or special handling of different types.

Lit Element is also a very clever usage of tagged templates.

Post reply on HN