Live data from Hacker News

Ask HN: Let's build Checkstyle for Bash?

news.ycombinator.com

61–70 of 71 posts

Re: Ask HN: Let's build Checkstyle for Bash?

#61
post #53

I've always been confused that in ${current_year} people are still directly writing huge + complex shell scripts. Compare/contrast Javascript, another language we're "stuck with": while you can still directly write it, many people don't, instead using transpilers to target Javascript as an "object code" from some other, stricter language (e.g. TypeScript, ClojureScript, arbitrary native languages via Emscripten / WAS…

This has been tried before. One of the results is autoconf.

At the end of the day, it's probably less painful to just bootstrap some saner interfaces if you really need them. The POSIX C API is just as standardized and exposes more than the shell interfaces.

Re: Ask HN: Let's build Checkstyle for Bash?

#62

Earlier quoted context omitted.

Where do you draw the line as "large"? I just threw out a few hundred lines of Python in exchange for ten lines of bash script + cron job to automate nightly app updates. Way easier to get working, way less painful to debug. I grant, however, that it's not particularly large. What is?

So your 10 lines of bash use a bunch of other programs to do almost all the work, right? So what you need is a good language that lets you concisely express ways of calling out to other programs. Not necessarily a language that's backward-compatible with whatever seemed like a good idea for a CLI in 1979.

Can you recommend any modern glue languages with the following attributes?

- concise (another operator instead of '|' is fine, but no extra parentheses, quotes etc.)

- performant (at least as fast as Bash)

- standalone (extensions discouraged)

Re: Ask HN: Let's build Checkstyle for Bash?

#63
post #51

Earlier quoted context omitted.

What do you use the; if you want: - Self contained in one file - Easily edited with vi/nano (i.e. through a console ssh session) - Readily available on most Linux base installations - No crazy runtime installation requirements Edit: formatting)

Some context to my statements: I'm a SWE that works on infrastructure services and tooling, primarily on Linux but also Unixes. It depends on what I'm doing but usually Go if an application requires any longevity at all. I use Python or Java for things that require more dynamic typing. The main usecase here is big data or to prototype applications. Bash I usually reserve for very small tasks. When I bootstrap service…

About the requirements and "single document":

Those tasks that I use bash for are usually one-offs, and live on the server they are used on.

Thus, it should be easy for the next admin/Dev to find it and understand/fix/extend it.

Of course, if there is a more advanced task those requirements fall short and there should be a proper Dev env with source control, tests, etc.

Re: Ask HN: Let's build Checkstyle for Bash?

#64
This is a neat idea, but I'm not sure I see the need for this specific tool. Shellcheck covers essentially all the errors that are mentioned in the Google Style Guide so I'd just be using that instead.

And as the Guide itself, it is mostly OK, but there are a few things I really don't like. For example:

- Whatever doc format they use is not as nice to use as shdoc. Namely, you don't have to add the spaces to your comment to make it formatted properly

- The 'no tabs' thing is pretty bullshit - Bash is literally the perfect language to use tabs and their "Whatever you do, don’t use tabs" comment really kills me

- I don't like their recommendation of using `[[`. Only using `[[` for stuff like regex and glob matching makes it much easier to paste code between Bash and POSIX sh.

There are also a few things they forgot to mention, like the lastpipe` shopt option when talking about piping while loops. And maybe it would be nice to recommend using local like `local var=`. But I guess this guide is meant more for new people that don't know all the pitfalls and stuff

But I think I agree there is some need for a more extensible linter. I've been eyeing the Bash LSP, which is based off the Bash Tree Sitter parser, but that has quite a few bugs with parsing that I've been meaning to send PR's for.

I wonder if `shfmt` has gotten better since I used it. A few years ago, it was quite buggy with prepending extra whitespace whenever I formatted the file

Re: Ask HN: Let's build Checkstyle for Bash?

#65
post #11

I think we should really be working to deprecate large bash scripts. If you write enough to care about code quality you might want to just use Python. I'd say look at things like Oil(Is that project ever going to be the next big thing like it claims?).... but writing large scripts in ANY shell doesn't seem like the best plan. What about an Ansible linter? Do those exist? I'm starting to suspect Ansible might be a bet…

> I think we should really be working to deprecate large bash scripts. I second this: I myself have a problem here, which, I guess is somewhat related: I try to keep everything universal and each time I try to generalize what I'm trying to achieve through some sort of abstraction. As a consequence I keep adding functions and aliases to my (zsh/bash)rc to the point where they become absolutely unmanageable. At this ve…

Wow, 8 thousand lines is pretty insane. When my bashrc started to get long, I started to separate things into different files and source them. And then that got too complicated so then I made them separate executables with different directories. But then I couldn't reuse functionality as easily so then I found myself making a package manager. And now I'm moving some of that stuff _BACK_ into my bashrc (sort of). It seems there is really no end...

Re: Ask HN: Let's build Checkstyle for Bash?

#66
post #53

I've always been confused that in ${current_year} people are still directly writing huge + complex shell scripts. Compare/contrast Javascript, another language we're "stuck with": while you can still directly write it, many people don't, instead using transpilers to target Javascript as an "object code" from some other, stricter language (e.g. TypeScript, ClojureScript, arbitrary native languages via Emscripten / WAS…

Sane people don't write shell scripts. I script everything little more complex with Ruby/JS.

Re: Ask HN: Let's build Checkstyle for Bash?

#67
post #53

I've always been confused that in ${current_year} people are still directly writing huge + complex shell scripts. Compare/contrast Javascript, another language we're "stuck with": while you can still directly write it, many people don't, instead using transpilers to target Javascript as an "object code" from some other, stricter language (e.g. TypeScript, ClojureScript, arbitrary native languages via Emscripten / WAS…

Oh people have tried - here are a few https://stackoverflow.com/questions/10239235/are-there-any-l...

I vaguely remember quite liking bish when I saw it years ago https://github.com/tdenniston/bish but it looks like no commits in 6 years.

This shelljs thing looks more promising, but really tedious to use https://github.com/shelljs/shelljs - shell.rm('-rf', 'out/Release'); I'd rather suffer proper bash than have to do that sort of thing.

Nothing seems to have really caught on so far. Bash is easy to learn and hack on, and before you know it, that simple install.sh that started out moving a few files around is 5000 lines, unmaintainable, and critical to bootstrapping your software :)

Re: Ask HN: Let's build Checkstyle for Bash?

#68
post #51

Earlier quoted context omitted.

Some context to my statements: I'm a SWE that works on infrastructure services and tooling, primarily on Linux but also Unixes. It depends on what I'm doing but usually Go if an application requires any longevity at all. I use Python or Java for things that require more dynamic typing. The main usecase here is big data or to prototype applications. Bash I usually reserve for very small tasks. When I bootstrap service…

About the requirements and "single document": Those tasks that I use bash for are usually one-offs, and live on the server they are used on. Thus, it should be easy for the next admin/Dev to find it and understand/fix/extend it. Of course, if there is a more advanced task those requirements fall short and there should be a proper Dev env with source control, tests, etc.

Ah, makes total sense. I was conflating the single document requirement with the original post which was seemingly trying to build a CLI tool.

Re: Ask HN: Let's build Checkstyle for Bash?

#69
post #53

I've always been confused that in ${current_year} people are still directly writing huge + complex shell scripts. Compare/contrast Javascript, another language we're "stuck with": while you can still directly write it, many people don't, instead using transpilers to target Javascript as an "object code" from some other, stricter language (e.g. TypeScript, ClojureScript, arbitrary native languages via Emscripten / WAS…

This has been tried before. One of the results is autoconf. At the end of the day, it's probably less painful to just bootstrap some saner interfaces if you really need them. The POSIX C API is just as standardized and exposes more than the shell interfaces.

That assumes you're targeting systems with a local compiler toolchain. A valid assumption for autotools itself, but "having a C compiler available" isn't a requirement of POSIX. (POSIX merely standardizes the interface that such a toolchain should present, if one is available.)

I reiterate my example: the install.sh for the Linux edition of VMWare Workstation. Its job is to take an arbitrary machine running a desktop Linux OS (i.e. it does assume an X installation), and turn it into a hypervisor dom0.

To do this, it needs to compile its proprietary Linux kernel modules using DKMS. But 1. it can't assume that you have a compiler toolchain installed; and 2. it can't assume that you have the kernel header package installed for your kernel.

So this install script needs to detect your OS distro-family, and use that to determine how to forcibly install some packages, in order to then have the tools (and headers) available to compile things.

How would you suggest that this installation logic be implemented? Because right now it's "thousands of lines of extremely grody Bourne shell script" — and AFAICT, that's because that was the optimal choice given the problem domain.

I suppose you could build such an installer as a collection of static binaries, one for each architecture. (Static, because different distros name their libs differently, so dynamic linkage isn't portable.) You could then create a little install.sh that runs them.

And, if you wanted all this to be tucked into a single file so you could run it with the unsafe curl-to-shell hack, you could even base64-armor those binaries and drop them into some heredocs inside a bootstrap shell-script, such that you do get to have a single "install.sh", which just pops out copy of the 'correct' binary into existence and runs it.

But IMHO, by doing something like this, you're just Greenspunning a Bourne-shell object-code format; the same one a compiler could emit. But without the benefit of getting to directly use a linker to generate the result.

Re: Ask HN: Let's build Checkstyle for Bash?

#70
post #11

I think we should really be working to deprecate large bash scripts. If you write enough to care about code quality you might want to just use Python. I'd say look at things like Oil(Is that project ever going to be the next big thing like it claims?).... but writing large scripts in ANY shell doesn't seem like the best plan. What about an Ansible linter? Do those exist? I'm starting to suspect Ansible might be a bet…

> I think we should really be working to deprecate large bash scripts. I second this: I myself have a problem here, which, I guess is somewhat related: I try to keep everything universal and each time I try to generalize what I'm trying to achieve through some sort of abstraction. As a consequence I keep adding functions and aliases to my (zsh/bash)rc to the point where they become absolutely unmanageable. At this ve…

This is one of the reasons I like GUIs. I can recreate almost all my configuration from scratch on a brand new Mint install in 15 minutes aside from a few VS code settings I'd need Google for.

My .xonshrc just has a few visual tweaks. I have set up exactly zero cron jobs aside from maybe whatever mint's backup stuff uses for a timer for the snapshots. I don't have any custom bash scripts that I use, other than some build scripts and things like that, that live in project repos.

I call it "decustomizing" as a counterpoint to minimalism. I don't try to simplify my life, I try to remove customization and unusual tech, even if that means using a 100MB app instead of a 1kb script I'd have to maintain myself.

I've just... had about enough of small time garage tinkering level projects at this point, and have really started to appreciate monolithic opinionated systems. Stuff that lets you do anything, in exactly one way.

Post reply on HN