Live data from Hacker News

Why doesn't Bash’s ‘set -e’ do what I expected? (2021)

mywiki.wooledge.org

71–80 of 114 posts

Re: Why doesn't Bash’s ‘set -e’ do what I expected? (2021)

#71

Because bash error handling is a thousand blades and no handle. https://blog.habets.se/2021/06/The-uselessness-of-bash.html I've reviewed a lot of code, bash and otherwise. I have never, not once, reviewed bash code that didn't have subtle bugs. And this is code written by smart people.

> Because bash is thousand blades and no handle.

FTFY.

It really is absolutely terrible tool as programming language. If your script is more than "a bunch of pipes in a trench coat" just use something else. I'd unironically prefer Perl to it.

Re: Why doesn't Bash’s ‘set -e’ do what I expected? (2021)

#72
post #66

Short answer: because it's Bash. No syntax or language construct will do what you expected.

I tend to think of Bash as a syntax-free language. There are no clear rules, you just have to kind of make it work every time. It's like the programming version of a freestyle rap or Parkour.

Hell, Perl is at least consistent in its insanity

Re: Why doesn't Bash’s ‘set -e’ do what I expected? (2021)

#73

In the 2000s, I was running extensive sets of simulations and data reduction scripts for a scientific experiment, and I was heavy relying on scripts to run the programs, collect the results, and distribute them over several servers. At first I developed those scripts using bash, but I needed to do math and complex iterations over file names and different parameter files, and I continuously stumbled upon weird behavio…

Wait till you learn about Python lmao

For simplish parallel runner https://www.gnu.org/software/parallel/ is excellent, can even automate stuff like "copy a file to remote server then run command on it" so you can make simplistic cluster computing with it

Re: Why doesn't Bash’s ‘set -e’ do what I expected? (2021)

#74
post #71

Because bash error handling is a thousand blades and no handle. https://blog.habets.se/2021/06/The-uselessness-of-bash.html I've reviewed a lot of code, bash and otherwise. I have never, not once, reviewed bash code that didn't have subtle bugs. And this is code written by smart people.

> Because bash is thousand blades and no handle. FTFY. It really is absolutely terrible tool as programming language. If your script is more than "a bunch of pipes in a trench coat" just use something else. I'd unironically prefer Perl to it.

Of course it's not ironic. Perl's raison d'entre is to replace bash+grep+sed+awk

Re: Why doesn't Bash’s ‘set -e’ do what I expected? (2021)

#75
post #66

Short answer: because it's Bash. No syntax or language construct will do what you expected.

I tend to think of Bash as a syntax-free language. There are no clear rules, you just have to kind of make it work every time. It's like the programming version of a freestyle rap or Parkour.

It's more of a pidgin. Syntax and semantics made up on the fly to suit the need of the moment, and then made permanent once used. No overarching design or consistency.

Re: Why doesn't Bash’s ‘set -e’ do what I expected? (2021)

#77
post #73

In the 2000s, I was running extensive sets of simulations and data reduction scripts for a scientific experiment, and I was heavy relying on scripts to run the programs, collect the results, and distribute them over several servers. At first I developed those scripts using bash, but I needed to do math and complex iterations over file names and different parameter files, and I continuously stumbled upon weird behavio…

Wait till you learn about Python lmao For simplish parallel runner https://www.gnu.org/software/parallel/ is excellent, can even automate stuff like "copy a file to remote server then run command on it" so you can make simplistic cluster computing with it

parallel is even great for non-parallel things because of its simple CLI handling and transformation of filenames (`{}`, `{.}`, `{/}`, etc.)

e.g. `ls old/*.jpeg | parallel mv {} new/{/.}.jpg` is easier than a bash loop.[1]

[1] Yes, it should be `find -print0` or something, blah blah, it's an example.

Re: Why doesn't Bash’s ‘set -e’ do what I expected? (2021)

#78
post #56

I can highly recommend using Shellcheck [0] when writing Bash, it also has extensions for VS Code and other IDE's. It makes writing Bash much easier. [0] https://github.com/koalaman/shellcheck

I moved over to shellharden a while ago. It can actually apply the suggestions it makes. Aside from that, my employer is somewhat disapproving for GPLv3 tools, but MPL that shellharden uses is essentially auto-approved.

https://github.com/anordal/shellharden

Re: Why doesn't Bash’s ‘set -e’ do what I expected? (2021)

#79

What's the best and smallest choice to replace admin/ops bash scripts ? Python ? Python with some lib ? Ruby ? Lua ? Rust ?

IMO, Perl is perfect for this purpose. A good thing about Perl is, it doesn't really changed any more. So no need to spend time keeping up with latest developments like Ruby or Rust.

Re: Why doesn't Bash’s ‘set -e’ do what I expected? (2021)

#80
post #56

I can highly recommend using Shellcheck [0] when writing Bash, it also has extensions for VS Code and other IDE's. It makes writing Bash much easier. [0] https://github.com/koalaman/shellcheck

I moved over to shellharden a while ago. It can actually apply the suggestions it makes. Aside from that, my employer is somewhat disapproving for GPLv3 tools, but MPL that shellharden uses is essentially auto-approved. https://github.com/anordal/shellharden

> my employer is somewhat disapproving for GPLv3 tools

Let's hope it's not bash scripts you're writing :-)

http://git.savannah.gnu.org/cgit/bash.git/tree/COPYING

Post reply on HN