top | item 42351152

(no title)

JoyfulTurkey | 1 year ago

Dealing with this at work right now. Digging through thousands of lines of Bash. This script wasn’t written a long time ago, so no clue why they went with Bash.

The script works but it always feels like something is going to break if I look at the code the wrong way.

discuss

order

chubot|1 year ago

If you have thousands of lines of bash, don't like maintaining it, but don't necessarily want to rewrite the whole thing at once, that's what https://www.oilshell.org/ is for!

See my comment here, with some details: https://news.ycombinator.com/item?id=42354095

(I created the project and the wiki page. Right now the best bet is to join https://oilshell.zulipchat.com/ if it interests you. People who want to test it out should be comfortable with compiling source tarballs, which is generally trivial because shells have almost no dependencies.)

The first step is:

    shopt --set strict:all  # at the top of the file
Or to run under bash

    shopt -s strict:all 2>/dev/null || true
And then run with "osh myscript.bash"

OSH should run your script exactly the same as bash, but with better error messages, and precise source locations.

And you will get some strictness errors, which can help catch coding bugs. It's a little like ShellCheck, except it can detect things at runtime, whereas ShellCheck can't.