Live data from Hacker News

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

news.ycombinator.com

51–60 of 106 posts

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

#52
post #48

Can you be more specific than "fatigue"? That sounds like ennui, in which case maybe consider a job switch instead of a language switch (not being sarcastic or intentionally mean). Bash plus all the Unix tools (awk, grep, sed, tsort, comm, the ones I don't know, etc.) have pretty long legs, in terms of functionality and the syntax is pretty understandable. They provide most of what Perl offers, apart from OO (-ish) a…

> If you want strong typing (are you scripting in the large?), then, almost by definition, no scripting language provides that.

Powershell is basically strongly typed.

> Can you be more specific than "fatigue"? That sounds like ennui

I love my job, but bash makes me wanna hang myself. I can say the same about stored procedures. Its like going back to cobol days. Some people have strong tastes I guess.

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

#53
I don't think the breaking point is the number of lines in the script; your pain point is probably one or two specific concepts or features? (or lack of)

Shell is likely to remain the best way to connect together other pieces of software.

The tipping point, in my experience, is folks trying to use arrays or other buffering of data. At that point they're writing in shell, but wishing for a procedural language.

Whereas, shell works excellently (and incredibly efficiently) if you can compose your task strictly into streams of data (a more 'functional' feel)

So the real answer I think is specific to the types of script you are writing!

But also it could be worth revisiting the style in which you're using shell; especially if you can call upon your own helper programs (eg. in Python) where you require buffering or non-streamed access to data.

Whilst there's a lot of documentation of sh/bash functionality, I don't think there's anything like the same momentum behind 'best practices' as other languages like Python or even C.

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

#54
The question you should ask yourself is not what use instead of bash but what is the problem you are trying to solve and what is the best way to solve it.

It's hard for us to help you with you giving us some context.

150-500 loc of bash are not that much, specially when you combine bash with standard Unix utilities.

These scripts you wrote, for what do you use them? Are they executed by humans or machines? On which platform? Linux, Mac, Windows or all?

You mentioned jq. Are you parsing json from HTTP requests or files? And why are you parsing json with bash?

Without a better context, A lot of people will say to use Python and Python is a good choice with you are running you scripts on Linux because you probably already have Python 3 installed and whatever you are writing with 500 loc of bash can be accomplished with zero dependencies with Python standard library.

If relying on the Python runtime is really a problem for you, your next best option is Go. Go is easy to learn and easy to use for building small cli apps with only the standard library, but even if you need some dependency, you will ship a single binary, so no problems with runtime compatibility or dependencies.

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

#55
post #45

Earlier quoted context omitted.

Assuming you're deploying to the same OS/architecture that you're working from, otherwise you'd have to rebuild (which Rust makes easy to do, but still)

How easy is it to cross-compile with Rust?

Trivial. All of the tooling, dependency management, linking, etc. is neatly bundled together under cargo. Just run "cargo build" for the current system, or specify one or more other architectures as arguments to get multiple binaries. Everything's statically-linked so you should be able to scp those wherever.

Still, when we're talking about casual "scripts" even this extra step seems a little bit burdensome

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

#57

With nix you can make anything into a script, there's some people using haskell for example. I tend to use common lisp but I'm learning guile scheme and will probably move to that instead.

I don't understand (even though Nixos was my only OS for a couple of months). How would Nix help me make Haskell into a script?

I think OP means that it would allow you to pull it from anywhere you have nix installed...

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

#58
Like others said it depends on each problem you are solving. Consider Java, nodejs, go, rust, ruby, python, c# - the one you know best is the best. Build up some Util classes for stuff you do regularly. NPM has a package for everything eg there is a cron so I like it for that reason.

Consider docker for some situations. Consider kubernetes if the need is more devops/ running a production system.

Consider powershell if on windows.

Travis ci / Jenkins / appveyor etc. for CI

Be lazy - can I get out of writing this code should be in the forefront of your mind (for any code!). The answer might be no but consider it.

No code tools can be considered - Google sheets, Wordpress, plethora of saas to do this. Paas eg aws lambda etc.

So many options. Solve the problem, rather than transliterate bash.

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

#60

With nix you can make anything into a script, there's some people using haskell for example. I tend to use common lisp but I'm learning guile scheme and will probably move to that instead.

I don't understand (even though Nixos was my only OS for a couple of months). How would Nix help me make Haskell into a script?

https://github.com/BrianHicks/nix-script

This was on HN the other day. Nix allows you to crunchbang a `nix-shell -p` kind of expression.

Post reply on HN