Live data from Hacker News

Ask HN: What to use instead of Bash / Sh for scripting?

news.ycombinator.com

31–40 of 106 posts

Re: Ask HN: What to use instead of Bash / Sh for scripting?

#31
A configuration management system may have you write e.g. YAML with Jinja2 so that you don't reinvent the idempotent wheel.

It's really easy to write dangerous shell scripts ("${@}" vs ${@} for example) and also easy to write dangerous Python scripts (cmd="{}; {}").

Sarge is one way to use subprocess in Python. https://sarge.readthedocs.io/en/latest/

If you're doing installation and configuration, the most team-maintainable thing is to avoid custom code and work with a configuration management system test runner.

When you "A shell script will be fine, all I have to do is [...]" and then you realize that you need a portable POSIX shell script and to be merged it must have actual automated tests of things that are supposed to run as root - now in a fresh vm/container for testing - and manual verification of `set +xev` output isn't an automated assertion.

Re: Ask HN: What to use instead of Bash / Sh for scripting?

#33
Perl (5). It's an incredibly capable scripting language, many things essential for Shell programming are much better integrated than in Python (e.g. regular expressions). It gets a lot of hate these days but it's still a damn fine language and perfectly suited to shell programming (and larger projects).

Re: Ask HN: What to use instead of Bash / Sh for scripting?

#34

Just use PowerShell. You can do so much in it without any dependency (jq is native in it and many other things). It is cross-platform so you can use your scripts anywhere. Don't use python or go or ruby or whatever as those are not scripting languages. IMO Bash is horror and should die already.

Powershell is a horror you mean, it's got the verbosity of objective c with the consistency that comes with all Microsoft designed products.

Just use a proper scripting language.

Re: Ask HN: What to use instead of Bash / Sh for scripting?

#35

Just use PowerShell. You can do so much in it without any dependency (jq is native in it and many other things). It is cross-platform so you can use your scripts anywhere. Don't use python or go or ruby or whatever as those are not scripting languages. IMO Bash is horror and should die already.

Powershell is a horror you mean, it's got the verbosity of objective c with the consistency that comes with all Microsoft designed products. Just use a proper scripting language.

No, I said what I mean. Bash and its disasters like [ as executable and mega error prone and awkward language designed 50 years ago IS horror.

Verbosity of powershell is optional, I don't use it.

> consistency that comes with all Microsoft designed products.

Oh, lets not troll here.

Re: Ask HN: What to use instead of Bash / Sh for scripting?

#36

I really like NodeJS for more complex system-scripting. In contrast with Python: 1) There aren't two disjoint versions to juggle 2) Dependency installation is clean and contained 3) Dependencies can easily be installed locally or globally, depending on your preference for isolation vs reuse 4) Lots of packages are available for doing cross-platform (read: Windows compatible) operations 5) JS makes it really easy to d…

JavaScript as a shell replacement, what a time to be alive! I am familiar with and use quite a bit of js on the front end, but how is node for shelling out? This is something I find Python to be quite terrible at.

Let me put it this way; I recently wrote a script to parse the output of last and format it.

The Node version was some 90 LoC but if I included the dependencies it came to about 5 MB. Then I rewrote the same script in Python3 and it was 60 LoC and no dependencies that needed to be installed separately.

I will admit that the JS code looked _a lot_ cleaner than the the Python code though.

Re: Ask HN: What to use instead of Bash / Sh for scripting?

#37

Perl (5). It's an incredibly capable scripting language, many things essential for Shell programming are much better integrated than in Python (e.g. regular expressions). It gets a lot of hate these days but it's still a damn fine language and perfectly suited to shell programming (and larger projects).

One of the things about Perl is that I can't quite believe myself how far it has fallen.

I was never a Perl monk by any means but I knew enough to get by. And why did I not even think about it? I haven't coded Perl in years, but if my memory serves me correctly, bundling extra dependencies in Perl was a heck of a lot less painful than Python too.

Re: Ask HN: What to use instead of Bash / Sh for scripting?

#38

I really like NodeJS for more complex system-scripting. In contrast with Python: 1) There aren't two disjoint versions to juggle 2) Dependency installation is clean and contained 3) Dependencies can easily be installed locally or globally, depending on your preference for isolation vs reuse 4) Lots of packages are available for doing cross-platform (read: Windows compatible) operations 5) JS makes it really easy to d…

JavaScript as a shell replacement, what a time to be alive! I am familiar with and use quite a bit of js on the front end, but how is node for shelling out? This is something I find Python to be quite terrible at.

Node is great for shell scripts. Async programming is a breeze in JavaScript. I wrote a quick wrapper function around child_process.exec to promisify it, and this allows me to use features like async / await and Promise.all in my scripts.

Re: Ask HN: What to use instead of Bash / Sh for scripting?

#39
Next Generation Shell was born exactly out of the pain of using bash and Python. I'm the author and I felt the same way.

> shelling out when needed is not pleasant,

Handled properly because the language was built ground up for Ops tasks. There is even a syntax for "run a command and parse the output". Rationale and examples - https://ngs-lang.org/doc/latest/man/ngswhy.1.html

Currently NGS supports Linux and MacOS.

> smallish binary

Unfortunately there is no static build yet so can't check this checkbox

Next Generation Shell - https://github.com/ngs-lang/ngs

Alternative Shells list by @chubot - https://github.com/oilshell/oil/wiki/Alternative-Shells

Re: Ask HN: What to use instead of Bash / Sh for scripting?

#40

I really like NodeJS for more complex system-scripting. In contrast with Python: 1) There aren't two disjoint versions to juggle 2) Dependency installation is clean and contained 3) Dependencies can easily be installed locally or globally, depending on your preference for isolation vs reuse 4) Lots of packages are available for doing cross-platform (read: Windows compatible) operations 5) JS makes it really easy to d…

I tend to write a lot of bash, partially for masochistic reasons, but I would probably choose Node over Python in 2021 for basic dev tooling scripts. Setting up a node environment with nvm can be done in a few lines of code, and it’s pretty reliable across platforms. Python is just too difficult to support consistently.

Really you should pick whatever you currently have in your codebase. We happen to have both Python and Node, with the languages generally being developed separately by different devs. So we’ve got tools in both, but a Node developer is unlikely to ever need/use the Python tools (although they can all run in Docker anyway). What annoys me a bit is that pre-commit requires a Python env to bootstrap itself, but it can install nvm without any fuss.

Post reply on HN