5 ms·
Why is Javascript a « perfect choose » for shell scripts?
by Diti 5y ago
Why is Javascript a « perfect choose » for shell scripts?
- abiro 5y agoI thought that was weird too. I much prefer Python to JS for scripting.
- Mauricebranagh 5y agoOr 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.
- goatlover 5y agoJavascript all the things.
- artificial 5y agoWhen the only tool you have is a hammer :)
- bryanrasmussen 5y agoYou look like Thor!
- Mauricebranagh 5y agoMore like Jeremy Clarkson hitting thing with a hammer instead of the right tool for the job.
- giorgioz 5y agoJS 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.
- EvilEy3 5y ago> and server side. Cool story.
- Shacklz 5y agoI 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.
- dehrmann 5y agoI 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.
- throw_m239339 5y ago> 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.
- Shacklz 5y agoFor 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.
- throw_m239339 5y ago> 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...
- deleted 5y ago[deleted]
- kristopolous 5y agoThis 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.