Hacker News new | past | comments | ask | show | jobs | submit login

Why is Javascript a « perfect choose » for shell scripts?



I had very strong anti-javascript opinions for the longest of times, and still feel that writing any non-weekend-project in JS is a mistake.

That being said, I have grown very fond of writing "plumbing"-scripts in nodeJS. The syntax is so much more sane than bash, the documentation of nodeJS is actually pretty good in my opinion, and once nodeJS is installed and available, its super easy to mash something together to get working. For small scripts, the uglier parts of JS do not really matter, and while nodeJS does have some APIs that feel a bit odd to use at times, it's at least well-documented with examples/guides all over the web.

Some folks use python for that exact purpose, but I always felt that getting something going takes me more effort than nodeJS (the fact that I'm just not fond of Python as a language might also have something to do with this).

All in all... for folks still using bash, I really recommend to give JS a try.


I prefer Python for this because more OSes ship with it, it has a fairly rich standard library, and SREs are more comfortable with it, so you're more likely to find others using it as glue.


This will probably not be particularly popular with the HN crowd, but PHP is also a surprisingly capable general purpose scripting language.

It's pre-installed on a lot of systems, backwards compatibility is good, and despite the inconsistencies, the standard lib can do a lot of stuff.


Agree, but it would be nice to have access to the entire composer community without setting up a composer environment, so not to toot my own horn, but I wrote proof of concept script to download PHP composer dependencies by parsing comments from the PHP script itself.

https://gist.github.com/tored/b500eb7c10fbabbe2043126e51caf2...

It would be nice to have something like this more integrated within the shell or maybe composer itself.


> I prefer Python for this because more OSes ship with it, it has a fairly rich standard library,

I mean nodejs =/= javascript, the problem is nodejs and some of the people who designed it who basically made it so that it would rely heavily on NPM, a commercial solution, thanks to the virtually non existing standard library. Now Microsoft virtually owns Nodejs since it owns NPM. Nodejs creator himself regretted this decision, publicly.


For what I called "plumbing"-scripts above, I rarely ever need any dependencies via npm. What nodeJS delivers out of the box suffices completely.

Sure, doing things like http directly with node is a bit cumbersome and having a library that does some abstraction comes in handy if you're working on something that goes way beyond what you'd ever consider doing in bash. But especially for that very purpose of things where I used nodeJS instead of using bash, nodeJS always had everything I needed out-of-the-box, almost never required any dependencies.

That being said, if you re-use code, plan to share scripts etc. with other people and all these things - using something like typescript (and possibly some testing-libraries) comes in very handy for maintainability, and there you can't get around npm. But for one-off-"plubming-scripts", nodeJS had all I ever needed.


Have you tried Typescript? It has one of the best type systems among mainstream (not FP) languages, IMO.


TS is probably my favorite language out there, so yes, I definitely did :)

But just for "one-off"-scripts, JS usually does the job pretty well. For bigger scripts or scripts where I want to reuse/share parts, typescript is an option - but it comes with a few hurdles: Most of the scripts I'm talking about work with zero npm-dependencies, while typescript adds at least one.

Furthermore, I either have to take care of compiling it, or use ts-node - one more dependency; and in both cases, I can't avoid the usual es6 vs. commonJS shenanigans. It's a bit of overhead to get going; always worth it if I spend more than a few hours on a script, but I can do without if it's just a few lines that I will hardly ever see again.


I think Deno may be a good choice in this use case: single binary that has a good standard-lib makes it seem like a good candidate for simple shell and pipeline scripting.


have a look at perl :)


> Why is Javascript a « perfect choose » for shell scripts?

It isn't, that project looks like perl re-invented but worse, since it mixes Javascript via nodejs and shell script syntax.

Shell scripts already support loops, functions, conditions, variables, ... it makes more sense to write a nodejs script that works as a regular shell process and include it in a shell script than the other way around...


JS is the most used language for web development both client and server side. It's easy to find fullstack repos with only JS code and a bunch of shell scripts to launch the tooling like webpack bundler and cypress e2e tester. By wrapping the tooling also in JS it's possible to take advantage of shared configuration written in JS and write reusable functions to share across scripts. Currently I have all my tooling scripts in bash (not yet in JS) and it's becoming hard to manage. Sharing functions and constant values across folders in shell bash script is very cumbersome.


> and server side.

Cool story.


I thought that was weird too. I much prefer Python to JS for scripting.


Or even Perl - I have only done some scripts in Python to use beautiful soup, or for scripts that may be used by less experienced developers.


This is purely performative and has no other benefit than to bow to a set of aesthetics.

It's merely doctrinal orthodoxy full of needless and ceremonious frivolities for the adherents to chin stroke in approval.

It is not, in any way, a reasonable way to do things, to exercise engineering, write maintainable or reliable code or otherwise accomplish tasks.

It is just spectacle.


Javascript all the things.


When the only tool you have is a hammer :)


You look like Thor!


More like Jeremy Clarkson hitting thing with a hammer instead of the right tool for the job.




Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: