Hacker News new | past | comments | ask | show | jobs | submit login

Bash/Sh is an objectively awful programming language. You could likely fill an entire book with all of the design fails that is Bash script syntax. Only in a shell script would you ever need eight backslash characters in a row in order to accomplish something...and "space as delimiter" is awful in so many ways.

But especially Sh runs everywhere, so it's good to know. This seems to be the article's point.

Honestly, though? The right answer is to transpile a better language to Sh.

Looking around, there have been several half-hearted, abandoned attempts. But apparently everyone is happy to just fall back on the "accidental syntax" of Bash that really doesn't make sense when compared to ... any other language.

I put up with Bash because there's no better alternative. That doesn't mean we should put up with Bash; just that we must put up with it at least to the point where it can run code written in a real language.




Bash is a user interface. The fact that you can string together words and symbols and make logic happen is basically just back-porting advanced user functionality into an existing interface.

Having said that, Bash is my favorite programming language, because it is so limiting, and simultaneously not limiting, because it wasn't designed to fulfill what A Real Programmer(TM) thinks a programming language should be.

A computer is supposed to serve a human. Not the other way around. But modern programmers, being wildly unimaginative creatures of habit, think the user is supposed to serve the computer. That the more you type, and the more hoops you jump through, the more "clever" you are with the "way" you tell the machine to do something, that this is superior. Never mind that the end result of all this incantation and tom-foolery doesn't actually result in a good outcome half the time. That the user is often unhappy with the result, if they even factor into the programmer's thinking at all. No, the true purpose of programming is to gratify the programmer and make the machine happy, not to make a human's life easier.

Programming is a mistake. It's a half-measure. A stutter in the evolution of digital computing. We weren't meant to program, we were meant to make a synthetic invention that relieved us of our labor. And what do we have to show for spending 1/3 of our life, and decades of work, for it? A metal and plastic box that can do pretty much exactly the same real work as 30 years ago, but with better graphics, because the hardware people gave us better screens.


There's almost nothing that computers do that isn't easier than the pre-computer way.

Look at it from an average user's perspective. They're thinking "Wow, this spreadsheet would have taken hours to do with a calculator and a pencil".

Most users are not programmers. Programming IS the act of making a synthetic invention that relieves us of our labor. It's no different from what a plumber does. If we had to connect pipes in a custom arrangement every time we wanted to do the dishes we would argue all day about the best pipes and threads and tapes.

But we don't. We use premade fixtures and we don't have to think about plumbing.

Those hoops you have to jump through are like the building codes. They make everything consistent. And more importantly, they make things inspectable. There are a million and one ways to plumb or frame a wall or something that would probably be fine. But that would be Real Engineering to do that and show that it's safe.

Wheras the codes are designed to not allow for "interesting" stuff that only an engineer would understand. The programming conventions developed over time based on programmers experience of what works and what doesn't when writing software that is so complicated not one person on earth could ever understand it.

The difference with programmers is they use programs to make programs. There's no user/designer distinction, and they all want to be creative and clever engineers, not just skilled tradespeople, so they don't see the benefits as much. If most of what you do is coding, you might thing nothing has advanced in the last 30 years, because you used text then and now you have more complicated text.

But from a user perspective, we went from drafting tables to CAD. We have Google Keep. We have voice assistants. We have 4k editing for consumers!

Bash pretty much just makes it explicit right in the language that there's no user/coder distinction and kind of keeps that mindset around.

Newer languages are designed to help people make user facing black boxes, and they do a great job of it it seems.


If only we had something like building codes, maybe we could stop fucking around trying to re-invent the building all the time, and just make a god damn building that didn't fall down after 3 months.

We make shit programs because our industry has no code, no apprentices, no journeymen, no masters. We have kids with no discipline who don't understand how anything works and just fake it 'til they make it. Everything from the shit designs to the inefficient basic programs to the overinflated titles to the lack of basic rigor shows that, generation after generation, we're actually getting worse at our profession, not better. We inherit good foundations and we shit on them. And we look at the people shitting stylistically and imitate them.

> we went from drafting tables to CAD. We have Google Keep. We have voice assistants. We have 4k editing for consumers!

We had CAD in the fucking 1960s!!! Google Keep is an overcomplicated frontend for RCS. I've literally programmed a better voice assistant in Perl in 1999. 4K isn't even usable on most devices, let alone necessary.

I literally knew more about software when I was 18 than any programmer I have met in the last 5 years. And I'm not that smart.

> Bash pretty much just makes it explicit right in the language that there's no user/coder distinction

Bash makes it explicit that there is no coder. There's only a user. Programmers don't seem to realize it, but the way they act, they don't consider that the user even exists. This is the defining characteristic of 21st century technology. Programmers are self-serving, and users are waiting for someone to make their lives easier. Like children waiting for the chefs to stop fucking around in the kitchen with sourdough starters and hydration ratios, and just bring out some god damn bread.


There was CAD in the 60s, but somewhere they have archives of paper plans for the moon landings. If it tried to use 60s cad I'd probably think it was just a drafting tool with some extras, not like modern cad with solvers, parametric modeling, and 3D views. I don't see how I could make a sketch with constraints on a face back then, modern CAD is slightly slow even on my laptop.

Deep learning voice recognition didn't exist in 1999, which is the critical tech that makes Assistant usable, along with the fact that there's now Keep to integrate with and IoT to control.

It's true that programmers hate users sometimes, but that's not an issue of tech or skill, that's an issue of programming culture is full of people who would like to go back to tech free simple living and mostly see computers as "bicycles for the mind" rather than "A UI layer for everything manmade we interact with" or "somewhat independent robots". They're in it for the exploration of thought, not because they want paying taxes to be fully automated.

But it's the managers and UI designers, and the small percent of programmers that don't hate tech, who actually direct a lot of the experience.

Bash is basically incapable of making anything I'd want as a user, because it's not good for managing insane amounts of complexity. It's a tool for directly controlling a computer and using it as a passive tool.

Modern languages are tools for essentially using the computer almost as a manager more than an employee, and for creating new models of interaction that the machine is better able to always have your back with.

If I want a block to be 35mm tall in total, but there's terraced layers and curves and stuff, I set a constraint.

I don't have to worry about the math. I'm not just virtually building stuff like a digital simulation of wood, I'm doing something completely synthetic, that was made up by someone who figured out a model for interacting that puts as much of the hard parts in the CPU instead of in the brain. It can't just be one way "I tell the machine what to do" interaction or the whole thing is limited to my own ability just like paper.

It can't be text based or anything else that requires mental translation, or I'd just have an extra task in addition to doing the whole design myself.

Modern software's solution is to create a way to think about the task that is inherently something suited for both humans and machines, and then to teach the user that way. Bash is freeform, it says "think how you want then translate it to what machines know".

It's great if you want control, not great for computer-led experiences.

Sadly it doesn't seem like we are designing many new paradigms of interaction, but I blame lack of interest rather than lack of tech ability. Programmers think about the functionality first, rather than about the interaction model, because they like ideas and dislike software used in the real world when a pencil could have done instead.

We do have building codes. Unit tests, memory safe languages, design patterns, DRY, reuse... It's just that lots of devs don't like them.


> Bash is a user interface.

Meh. That part is irrelevant in the extreme to the discussion.

Fact is that people write `.sh` and `.bash` scripts to get things done. They use conditional logic and loops and everything.

Functionally, it's a programming language with a (useful) REPL.

And this discussion is 100% about how bash is as a programming language.

> Having said that, Bash is my favorite programming language, because it is so limiting, and simultaneously not limiting, because it wasn't designed to fulfill what A Real Programmer(TM) thinks a programming language should be.

Umm... Then, yeah, I have to agree with your self-assessment of not being a "real programmer."

Sorry, but it's obviously true.

You're a scripter. I've known and worked with many scripters. They can do a lot of valuable work and contribute in a lot of ways to various projects. But they're not programmers.

Which is fine. Script away.

> But modern programmers, being wildly unimaginative creatures of habit, think the user is supposed to serve the computer.

After admitting you're not a programmer, you then go on to demonstrate that you don't really understand how programming works. Which I guess follows?

That's so far from the reality, that it's Not Even Wrong.

> That the more you type, and the more hoops you jump through, the more "clever" you are with the "way" you tell the machine to do something, that this is superior.

Programming languages are exactly the level of complexity needed to, with the least effort and most reliability, craft the code that, literally, civilization relies on.

It can't be made simpler. The complexity is inherent in the domain.

> Programming is a mistake. It's a half-measure. A stutter in the evolution of digital computing. We weren't meant to program, ...

YOU weren't meant to program. You admitted that above. Don't speak for the rest of us.

Everything significant in software that has been and will be accomplished moving forward will be created by programmers using programming languages. Your rant against programmers and programming is based on a lack of understanding of what programming really is and how programmers really think.

It's not even slightly about being clever. It's about the act of primal creation. We're effectively wizards of the modern world. We don't care at all about making a machine happy; we care about building things that work. That the things embody complexity isn't the goal, but it is a thing of beauty when it all works together elegantly.


Bash is a shell. A bad shell. Korn is a good shell.

It's not meant to be a real language. It's meant to be a shell. Here, let me back that up and reverse it for you.

<JAVA> public Set<String> listFilesUsingJavaIO(String dir) { return Stream.of(new File(dir).listFiles()) .filter(file -> !file.isDirectory()) .map(File::getName) .collect(Collectors.toSet()); } //I'm not handling errors, and this doesn't actually print anything, it just lets me try to.

<SHELL> ls

Shell is meant to be a common way to do common tasks on commandline, and make a little script if you want to save that and run it again. I can do little things in a shell one-liner quick, that would take a page of python or perl.

I put up with my sports car because there's no better alternative. It doesn't mean I should put up with a sports car for transporting my piano, just that I must put up with it at least to the point where the sports car can transport me to the car that transports a piano.


Bash is used as a programming language.

And it's an objectively awful programming language. Sh is even worse.

Korn isn't installed absolutely everywhere like Sh is. It's not even installed in 1/100 of the locations that Bash is installed. So it being better is irrelevant to the discussion of Bash as a programming language.

Because Bash is so awful, the only real justification for using it as a programming language is that it's already installed. Since Korn isn't already installed, that means you'd need to install it. If you're going to be installing something, there are far better choices.

So your comment doesn't at all contribute to the discussion of alternatives to using Bash as a programming language.

And the verbosity of using Java to list a folder contents is equally irrelevant. No one would argue that Java is better ... for listing directory contents.

If you do want to write a script that calls a bunch of shell commands, or even that operates on folders and files, there are far better languages and tools.

See, for example, https://www.npmjs.com/package/tish

Or just Node/TypeScript in general.


> "space as delimiter" is awful in so many ways

Yes. But it's also absolutely great in so many ways.


Until you utter the words:

Yoo-nee-kode


The main use case of a shell is interactive use. There is no reason to invoke a teanspiler when you type a command to be immediately executed. Often its syntax is a bit awkward because in needs to be compact and quick to type.

If you want a better language for complex scripts, use Python, or even Perl, they are now ubiquitous, or bring someting self-contained like Lua or Janet with you.

It would be great to have a different ubiquitous shell language on Unix machines, but it's unrealistic now.


There are two places a new shell language needs to be ubiquitous for success. One is installed on systems, which is pretty easy. With today's connectedness, new software is just an apt install, pacman, or curl | bash away. The other, much harder problem is that the people using the system need to know this new shell language. If I have to debug your shell script using Zsh, Csh, or Fish, I'm not going to be happy about it.


Shell is an interactive, concatenative string language with transparent file system access and binary execution capabilities. It doesn't need to be a general purpose programming language, because it's great at what it does. When I need something lower level, I can write that in low level and integrate into the shell language seamlessly.


There was an effort within Google SRE to use Go instead of bash for all the typical usages of bash. [1]

Cloudflare uses Go similarly as a scripting language. [2]

[1]: https://go.dev/solutions/google/sitereliability [2]: https://blog.cloudflare.com/using-go-as-a-scripting-language...


Also javascript as an alternative for bash..

Not an official Google product of course but ...

https://github.com/google/zx

>Bash is great, but when it comes to writing more complex scripts, many people prefer a more convenient programming language. JavaScript is a perfect choice, but the Node.js standard library requires additional hassle before using. The zx package provides useful wrappers around child_process, escapes arguments and gives sensible defaults.


"JavaScript is a perfect choice"? My goodness!


> Honestly, though? The right answer is to transpile a better language to Sh.

I like this, but I think it's even better to just escape sh entirely. If you are on a system that supports sh, it almost certainly has a c99 compatible compiler which can be used to install lua(JIT)? or another better scripting language. I wrote a little script idempotently installs lua 5.4 (that I tried to include but HN formatting messed up) and then runs a luascript embedded in a heredoc. The first time I ran it, it took 5.4 seconds to print "Hello, world!" including downloading the lua source code from their website and compiling the whole thing. The second time it took 11ms. I really see no great reason to continue using sh for anything new except for the purpose of installing something else.


"Install something else" is ... a nice idea?

But it's simply not realistic.

Examples:

- Embedded devices that may or may not have an internet connection

- Government classified networks that aren't allowed to grab ANY random software off of the internet

- Simply not wanting to add another dependency to an operation.

I'm a former Lua fan. I've ... written it off at this point. [1]

Honestly if I were to take the approach you describe, I'd likely instead have the shell script only look at the architecture and then choose one of 2-3 precompiled Go binaries. Talk about simple and fast...and the binaries could be hosted behind a firewall somewhere.

Or maybe I was thinking of it wrong. Just embed the various Go binaries into a tar file embedded right in the shell script[2], and choose the right one based on architecture. Done. :)

[1] https://realmensch.org/2016/05/28/goodbye-lua/

[2] https://www.xmodulo.com/embed-binary-file-bash-script.html


Bash and most alternatives are full of footguns. However, they are really convenient to glue together different components, e.g. a data preprocessing system.

Personally, the way I avoid footguns is to use a functional style. Filter instead of conditions and map instead of loops. GNU Parallel makes this straightforward, including distributed commands across machines! Aside, it is easy to emulate relational algebra with grep, sed, and awk.

A good essay describing some of the advantages of this approach is: http://widgetsandshit.com/teddziuba/2010/10/taco-bell-progra...


There are lots of better alternatives in almost all cases, just not super weird niche stuff.

A lot of things that one would use bash for involve servers, and there's Ansible for that, no need to use bash directly most of the time. If it were up to me, distros would include Ansible out of the box.

IMHO doing anything at all that's not programmatically repeatable isn't the best practice, so it's not like I want to be logging onto something and writing a quick script in Nano.

Outside of servers.... nobody uses Linux except embedded systems and FOSS enthusiasts. Nobody is paying me to do FOSS work, so I can just pretend that Pythonless systems don't exist.

Python does have some version compatibility issues, but for the most part it's stable, and at least it will crash with a traceback not a cryptic error code because you used some utility that had some nonstandard syntax for the flags.

On embedded, most of what you're doing is probably simple enough that if you do need to use sh you won't absolutely scream.


If running everywhere is actually a constraint (likely it’s not) and transpiling is a consideration, you could use Golang, that statically links and produces standalone binaries that run more or less anywhere. Though if you have a CD pipeline to transpile and deploy such, you likely have enough control over your environment already to have a less constrained choice to begin with.

Normally I’m not very fond of Gos verbosity, especially compared to bash, but i take anything over bash, it is just so filled with footguns, every single line has to be super carefully scrutinized. Note that I say this as someone actually quite good at it, not because I don’t understand it. In fact the more you learn, the more scared you get.


> "space as delimiter" is awful in so many ways

Lisp and Scheme would like to have a word . . .


I needed to learn Lisp in college.

I hate Lisp.

'nough said.


I completely seriously and unironically find bash to be absolutely beautiful.

So, no, it's not "objectively" awful. At most it's "subjectively" awful for some people.


Yes, yet 'set -x' in Bash is more useful than in any other languages I know. Because Bash is used to call utils so you see the partial trace of your script that you want to see, not the inside of the tools/utils that you don't want to see. In contrast in gdb for C++ you 'step' inside the STL implementation that most of the time you don't care about..


Ummm....

A debugger won't "step in" unless you..."step in" instead of "step over."

STL is also no longer a thing. There's only the C++ standard library. So I think you're dating your usage of C++ by ... a decade or more?


I'm not very knowledgeable in this area as I don't do much shell scripting, but isn't zsh supposed to be some kind of enhancement over bash? Does it suffer from the same issues?

Regardless, the idea of a language that transpiles to bash is kinda interesting.


zsh is much better.

And it's not installed by default on all systems. It's especially not installed on systems like Alpine.

The point was never to "find a better shell." It was to run install (or other) scripts with some level of logic absolutely anywhere.


ZSH is basically the same thing. For all intents and purposes it is basically the same thing. The best attempt I’ve seen to truly make a better shell is Nushell.

https://www.nushell.sh/


> Bash/Sh is an objectively awful programming language.

Subjectively, not objectively.


Use fish for interactive & functions, Python for longer scripts.


I don't choose bash because I am unaware of other languages. I choose it because it's already installed everywhere.

If I'm going to install a language/shell, I'll likely choose Node, Bun, or Go, depending.

Python isn't actually a much better language from a language design standpoint.


Shell is an objectively _difficult_ programming language. But difficult != awful. Pointy and ready to bite you if you make a tiny mistake? Yes. Ubiquitous and not going anywhere? Also yes.

But given that *nix tooling output defaults to text, it's hard to argue against a universal language that talks to all of it.


In the case of Bash, it's objectively difficult and awful.¹

¹I have manipulated arrays in Bash, proving this statement.


Shell works because it’s the ultimate interpreter.

You sus out what you need to do by hand and then convert your history into a script.


TBH I use Python REPL the same way whenever I encounter unknown new libraries, which is why it's my goto after Bash.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: