this post was submitted on 05 Mar 2025
1590 points (99.0% liked)

Programmer Humor

21150 readers
1136 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
top 50 comments
sorted by: hot top controversial new old
[–] wwb4itcgas@lemm.ee 1 points 10 hours ago

I have a confession to make: Unless shell script is absolutely required, I just use Python for all my automation needs.

[–] conditional_soup@lemm.ee 110 points 4 days ago* (last edited 4 days ago) (14 children)

Regex

Edit: to everyone who responded, I use regex infrequently enough that the knowledge never really crystalizes. By the time I need it for this one thing again, I haven't touched it in like a year.

[–] 9point6@lemmy.world 38 points 4 days ago

You get used to it, I don't even see the code—I just see: group... pattern... read-ahead...

[–] kameecoding@lemmy.world 30 points 4 days ago (1 children)

Most of regex is pretty basic and easy to learn, it's the look ahead and look behind that are the killers imo

[–] PoolloverNathan@programming.dev 10 points 4 days ago

(?=) for positive lookahead and (?!) for negative lookahead. Stick a < in the middle for lookbehind.

[–] Kissaki@programming.dev 11 points 4 days ago (1 children)

You always forget regex syntax?

I've always found it simple to understand and remember. Even over many years and decades, I've never had issues reading or writing simple regex syntax (excluding the flags and shorthands) even after long regex breaks.

[–] Akito@lemmy.zip 14 points 4 days ago (6 children)

It's not about the syntax itself, it's about which syntax to use. There are different ones and remembering which one is for which language is tough.

[–] Lehmanator@programming.dev 3 points 2 days ago

This is exactly it. Regex is super simple. The difficulty is maintaining a mental mapping between language/util <-> regex engine <-> engine syntax & character class names. It gets worse when utils also conditionally enable extended syntaxes with flags or options.

The hardest part is remembering whether you need to use \w or [:alnum:].

Way too few utils actually mention which syntax they use too. Most just say something accepts a "regular expression", which is totally ambiguous.

load more comments (5 replies)
load more comments (11 replies)
[–] 0x0@lemmy.dbzer0.com 59 points 4 days ago (5 children)

PSA: Run ShellCheck on your shell scripts. It turns up a shocking number of programming errors. https://www.shellcheck.net/

[–] HyperMegaNet@lemm.ee 7 points 3 days ago

Thank you for this. About a year ago I came across ShellCheck thanks to a comment just like this on Reddit. I also happened to be getting towards the end of a project which included hundreds of lines of shell scripts across dozens of files.

It turns out that despite my workplace having done quite a bit of shell scripting for previous projects, no one had heard about Shell Check. We had been using similar analysis tools for other languages but nothing for shell scripts. As you say, it turned up a huge number of errors, including some pretty spicy ones when we first started using it. It was genuinely surprising to see how many unique and terrible ways the scripts could have failed.

load more comments (4 replies)
[–] JTskulk@lemmy.world 14 points 3 days ago

Bash was the first language I learned, got pretty decent at it. Now what happens is I think of a tiny script I need to write, I start writing it in Bash, I have to do string manipulation, I say fuck this shit and rewrite in Python lol

[–] PrettyFlyForAFatGuy@feddit.uk 25 points 3 days ago

I still have to look up the exact syntax of ifs and whiles.

I've coded in bash for a while

[–] victorz@lemmy.world 30 points 4 days ago (10 children)

Ever since I switched to Fish Shell, I've had no issues remembering anything. Ported my entire catalogue of custom scripts over to fish and everything became much cleaner. More legible, and less code to accomplish the same things. Easier argument parsing, control structures, everything. Much less error prone IMO.

Highly recommend it. It's obviously not POSIX or anything, but I find that the cost of installing fish on every machine I own is lower than maintaining POSIX-compliant scripts.

Enjoy your scripting!

[–] UndercoverUlrikHD@programming.dev 9 points 3 days ago (3 children)

If you're going to write scripts that requires installing software, might as well use something like python though? Most Linux distros ship also ship with python installed

load more comments (3 replies)
[–] raldone01@lemmy.world 6 points 3 days ago* (last edited 3 days ago) (1 children)

I love fish but sadly it has no proper equivalent of set -e as far as I know.

; or return; in every line is not a solution.

load more comments (1 replies)
load more comments (8 replies)
[–] SpaceNoodle@lemmy.world 54 points 4 days ago (5 children)

Clearly you don't write enough bash scripts.

[–] CrazyLikeGollum@lemmy.world 17 points 4 days ago (4 children)

Or scripts for basically any other variant of the Bourne shell. They are, for the most part, very cross compatible.

load more comments (4 replies)
load more comments (4 replies)
[–] perishthethought@lemm.ee 46 points 4 days ago (4 children)

I don't normally say this, but the AI tools I've used to help me write bash were pretty much spot on.

[–] marduk@lemmy.sdf.org 20 points 4 days ago (1 children)

Yes, with respect to the grey bearded uncles and aunties; as someone who never "learned" bash, in 2025 I'm letting a LLM do the bashing for me.

[–] SpaceNoodle@lemmy.world 39 points 4 days ago (4 children)

Until the magic incantations you don't bother to understand don't actually do what you think they're doing.

[–] embed_me@programming.dev 41 points 4 days ago (1 children)

Sounds like a problem for future me. That guy hates me lol

load more comments (1 replies)
[–] MBM@lemmings.world 14 points 4 days ago (1 children)

I wonder if there's a chance of getting rm -rf /* or zip bombs. Those are definitely in the training data at least.

load more comments (1 replies)
load more comments (2 replies)
[–] SpaceNoodle@lemmy.world 17 points 4 days ago* (last edited 4 days ago)

Yeah, an LLM can quickly parrot some basic boilerplate that's showed up in its training data a hundred times.

load more comments (2 replies)
[–] cupcakezealot@lemmy.blahaj.zone 24 points 4 days ago (1 children)

every control structure should end in the backwards spelling of how they started

[–] grrgyle@slrpnk.net 17 points 4 days ago (1 children)

Once you get used to it it is kind of fun.

Shame about do though.

[–] cupcakezealot@lemmy.blahaj.zone 14 points 4 days ago

it could have been not since there's no try.

[–] umbraroze@lemmy.world 29 points 4 days ago (3 children)

There's always the old piece of wisdom from the Unix jungle: "If you write a complex shellscript, sooner or later you'll wish you wrote it in a real programming language."

I wrote a huge PowerShell script over the past few years. I was like "Ooh, guess this is a resume item if anyone asks me if I know PowerShell." ...around the beginning of the year I rewrote the bloody thing in Python and I have zero regrets. It's no longer a Big Mush of Stuff That Does a Thing. It's got object orientation now. Design patterns. Things in independent units. Shit like that.

[–] Kissaki@programming.dev 12 points 4 days ago (4 children)

I consider python a scripting language too.

load more comments (2 replies)
[–] coldsideofyourpillow@lemmy.cafe 19 points 4 days ago* (last edited 4 days ago) (3 children)

That's why I use nushell. Very convenient for writing scripts that you can understand. Obviously, it cannot beat Python in terms of prototyping, but at least I don't have to relearn it everytime.

[–] AnUnusualRelic@lemmy.world 23 points 4 days ago (14 children)

So the alternative is:

  • either an obtuse script that works everywhere, or
  • a legible script that only works on your machine…
load more comments (14 replies)
[–] Akito@lemmy.zip 12 points 4 days ago (7 children)

Nu is great. Using it since many years. Clearly superior shell. Only problem is, that it constantly faces breaking changes and you therefore need to frequently update your modules.

load more comments (7 replies)
load more comments (1 replies)
[–] KazuchijouNo@lemy.lol 25 points 4 days ago (2 children)

Today I tried to write bash (I think)

I grabbed a bunch of commands, slapped a bunch of "&&" to string them together and saved them to a .sh file.

It didn't work as expected and I did not, at all, look at any documentation during the process. (This is obviously on me, I'll try harder next time)

load more comments (2 replies)
[–] AI_toothbrush@lemmy.zip 18 points 4 days ago

Wait im not the only one? I think i relearned bash more times than i can remember.

[–] 6mementomorib@lemmy.blahaj.zone 9 points 3 days ago (2 children)

i used powershell, and even after trying every other shell and as a die hard Linux user I've considered going back to powershell cause damn man

[–] ronflex@lemmy.world 5 points 3 days ago

I am a huge fan of using PowerShell for scripting on Linux. I use it a ton on Windows already and it allows me to write damn near cross-platform scripts with no extra effort. I still usually use a Bash or Fish shell but for scripting I love being able to utilize powershell.

load more comments (1 replies)
[–] zarathustra0@lemmy.world 10 points 3 days ago (3 children)

No, Makefile syntax is more extreme.

load more comments (3 replies)
[–] baratheon@lemmy.world 9 points 3 days ago (2 children)

to be honest I agree and thought we would be using something more intuitive by now

load more comments (2 replies)
[–] shortrounddev@lemmy.world 12 points 4 days ago (1 children)

Unironically love powershell

load more comments (1 replies)
[–] jkercher@programming.dev 7 points 3 days ago

Meh. I had a bash job for 6 years. I couldn't forget it if I wanted to. I imagine most people don't use it enough for it to stick. You get good enough at it, and there's no need to reach for python.

[–] Blackmist@feddit.uk 14 points 4 days ago (4 children)

Maybe applies more to regex, the write only language.

load more comments (4 replies)
[–] Tungsten5@lemm.ee 12 points 4 days ago (5 children)

And I thought I was the only one… for smaller bash scripts chatGPT/Deepseek does a good enough job at it. Though I still haven’t tried VScode’s copilot on bash scripts. I have only tried it wirh C code and it kiiiinda did an ass job at helping…

load more comments (5 replies)
[–] brokenlcd@feddit.it 14 points 4 days ago (1 children)

Knowing that there is still a bash script i wrote around 5 years ago still running the entirety of my high scool lab makes me sorry for the poor bastard that will need to fix those hieroglyphs as soon as some package breaks the script. I hate that i used bash, but it was the easiest option at the time on that desolate server.

load more comments (1 replies)
[–] Gobbel2000@programming.dev 12 points 4 days ago (2 children)

So true. Every time I have to look up how to write a bash for loop. Where does the semicolon go? Where is the newline? Is it terminated with done? Or with end? The worst part with bash is that when you do it wrong, most of the time there is no error but something completely wrong happens.

[–] ClemaX@lemm.ee 13 points 4 days ago* (last edited 4 days ago) (3 children)

It all makes sense when you think about the way it will be parsed. I prefer to use newlines instead of semicolons to show the blocks more clearly.

for file in *.txt
do
    cat "$file"
done

The do and done serve as the loop block delimiters. Such as { and } in many other languages. The shell parser couldn't know where stuff starts/ends.

Edit: I agree that the then/fi, do/done case/esac are very inconsistent.

Also to fail early and raise errors on uninitialized variables, I recommend to add this to the beginning of your bash scripts:

set -euo pipefail

Or only this for regular sh scripts:

set -eu

-e: Exit on error

-u: Error on access to undefined variable

-o pipefail: Abort pipeline early if any part of it fails.

There is also -x that can be very useful for debugging as it shows a trace of every command and result as it is executed.

load more comments (3 replies)
load more comments (1 replies)
load more comments
view more: next ›