Hacker News new | ask | show | jobs
by generalizations 1276 days ago
ChatGPT has been amazing for all kinds of programming-adjacent things, even in my line of work where I asked it for help modifying the config file for a selfhosted gitlab instance.

> But [Bash] fucking sucks. Like, it’s truly awful to write [...]

As an aside, considering how basic the shell script actually was, I think this is a great example of being so intimidated by something that you don't actually try and use it - until you do, and discover it wasn't actually that bad. The hardest part was just discovering the incantations for interacting with Chrome - which was a fantastic demo of the power of ChatGPT.

5 comments

Bash isn't that bad... except there are 20 ways to do anything and 18 of them are wrong, but only 1% of online examples will use either of the two correct approaches and simply reading docs won't always clue you in about how the technique or syntax it's describing is actually subtly wrong and you should ~never use it.
I find integrating shellcheck into my text editor was one of the best things I've done for increasing my productivity when writing shell scripts.
Yep - in the same way that you want govet, eslint, rubocop etc - but to a higher degree, because bash hides subtle bugs as soon as you use a variable without knowing the quoting rules.
Yes, i did the same! I also recommend following Stephane Chazelas on stackoverflow. The guy is a shell wizard who writes multiple quality answers a day. He's also the guy who found the "shellcheck" vuln some years ago. Learned a lot by reading the RSS feed of his SO profile every day.
I've always been sheepish about this, but bash is my favorite programming environment! Not really because of any language features as such, more it's terseness and simplicity. Another big draw for me is bash's ubiquity. All of this makes bash the ultimate glue layer. That said, if a bash script goes longer than ten lines long I'll usually rewrite in python.
Bash _itself_ (or any other shell) is very small. You're talking about the ecosystem (shell + other command line utilities).

Commands like awk, find, grep, sed, cut and so many others are not strictly part of the language. They're external tools commonly provided by the operating system or distribution. That's why there are so many inconsistencies between their options.

Here are the very few commands that actually are part of any modern shell: cd, printf, test, read, command. The control structures (if/elif/fi, while/do/done, for/do/done, case/esac) are also part of the shell, so is declaring functions and fd redirection. Some shells might do more (bash itself has a handful of other builtins, dash has fewer, ksh has different ones).

Stuff like find, mv, cp and dd are very uniform across implementations and often don't change much, but they are external tools nonetheless.

Once you internalize this distinction, and start to see these external commands like npm packages, scripting gets a lot easier.

> Bash _itself_ (or any other shell) is very small. You're talking about the ecosystem (shell + other command line utilities).

I'm not so sure. They mentioned syntax, and the single biggest issue among my co-workers who don't like bash is that they think ' and " work like they do in python or javascript.

They mentioned "20 ways of doing things", I'm replying to that complaint.

Quoting is an issue if you don't understand the IFS and command expansion. It's an old fashioned style, but it is consistent and there's only one way of doing it (quoting every variable and subshell use).

Think of shell variables as non first-class citizens, they can only be used interpolated within a string, like "$var". The shellcheck tool enforces this perspective, which makes ' and " behave very much like python or JS.

To give a more solid example, they don't understand why

  npm test
works and why they don't need

  npm "test"
That's just lazy. How that works is on any shell man page. If you fiddle with it a little bit you figure it out:

    set -- "foo"
    echo $#
    set -- foo
    echo $#
    set -- "foo bar"
    echo $#
    set -- foo bar
    echo $#
Of course, people just want their commands to run and not learn a whole new language. Then I come back to my initial point: the language itself is small and easy to remember once you internalize it, what makes it scary is the umbrella of different command line utilities that _seems_ to be a part of the language but it's not.
User error.
> The hardest part was just discovering the incantations

Right, that’s why Bash sucks. A more extreme version of this is APL.

Bash isn’t APL bad. But it’s pretty bad!

yeah absolutely. I think interacting with chrome and also parsing/iterating files were hard parts that ChatGPT breezed through.
Also, the specific argument format that chrome expects has nothing to do with Bash.
that's a great point - totally agree on just gettin over the hump of intimidation to try it, and chatgpt makes that hump trivial