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.
You get used to it, I don’t even see the code—I just see: group… pattern… read-ahead…
Most of regex is pretty basic and easy to learn, it’s the look ahead and look behind that are the killers imo
(?=)for positive lookahead and(?!)for negative lookahead. Stick a<in the middle for lookbehind.
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.
Don’t let the gatekeepers keep you out. This site helps.
Nice! This is the one I use: https://regexr.com/
Though it appears to be very similar on the face of it.
No. Learn it properly once and you’re good. Also it’s super handy in vim.
interns gonna intern
This is one of the best uses for LLM’s imo. They do all my regex for me.
For me I spent one hour of ADHD hyper focusing to get the gist of regex. Python.org has good documentation. It’s been like 2 years so I’ve forgotten it too lol.
I just use the regex101 site. I don’t need anything too complicated ever. Has all the common syntax and shows matches as you type. Supports the different languages and globals.
PSA: Run ShellCheck on your shell scripts. It turns up a shocking number of programming errors. https://www.shellcheck.net/
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.
I wish it had a more comprehensive auto correct feature. I maintain a huge bash repository and have tried to use it, and it common makes mistakes. None of us maintainers have time to rewrite the scripts to match standards.
I honestly think autocorrecting your scripts would do more harm than good. ShellCheck tells you about potential issues, but It’s up to you to determine the correct behavior.
For example, how could it know whether
cat $fooshould becat "$foo", or whether the script actually relies on word splitting? It’s possible that$foointentionally contains multiple paths.Maybe there are autofixable errors I’m not thinking of.
FYI, it’s possible to gradually adopt ShellCheck by setting
--severity=errorand working your way down to warnings and so on. Alternatively, you can add one-off#shellcheck ignore SC1234comments before offending lines to silence warnings.For example, how could it know whether
cat $fooshould becat "$foo", or whether the script actually relies on word splitting? It’s possible that$foointentionally contains multiple paths.Last time I used ShellCheck (yesterday funnily enough) I had written
ports+=($(get_elixir_ports))to split the input sinceget_elixir_portsreturns a string of space separated ports. It worked exactly as intended, but ShellCheck still recommended to make the splitting explicit rather than implicit.The ShellCheck docs recommended
IFS=" " read -r -a elixir_ports <<< "(get_elixir_ports)" ports+=("${elixir_ports[@]}")
Then you’ll have to find the time later when this leads to bugs. If you write against bash while declaring it POSIX shell, but then a random system’s
shdoesn’t implement a certain thing, you’ll be SOL. Or what exactly do you mean by “match standards”?
Clearly you don’t write enough bash scripts.
Or scripts for basically any other variant of the Bourne shell. They are, for the most part, very cross compatible.
That’s the only reason I’ve ever done much of anything in shell script. As a network administrator I’ve worked many network appliances running on some flavor of Unix and the one language I can count on to be always available is bash. It has been well worth knowing for just that reason.
I wrote a script to do backups on a ESXi it uses Busybox’s ASH, one thing I learned after spending hours debugging my scripts was that ASH does not support arrays so you have to do everything with temporary files.
There actually is an array in any POSIX shell. You get one array per file/function. It just feels bad to use it. You can abuse ‘set – 1 2 3 4’ to act as a proper array. You can then use ‘for’ without ‘in’ to iterate over it.
for i; do echo $i; done.
Use shift <number> to pop items off.
If I really have to use something more complex, I’ll reach for mkfifo instead so I can guarantee the data can only be consumed once without manipulating entries.
Cool, good to know.
Enough is enough
I’ve had enough of these motherfucking scripts on this motherfucking PC!
When I bash my head into a wall, does that count?
Only if you scripted it
I don’t normally say this, but the AI tools I’ve used to help me write bash were pretty much spot on.
Yeah, an LLM can quickly parrot some basic boilerplate that’s showed up in its training data a hundred times.
For building a quick template that I can tweak to my needs, it works really well. I just don’t find it to be an intuitive scripting language.
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.
I consider python a scripting language too.

They’re all programming languages, they all have their places.
All scripting languages are programming languages but not all programming languages are scripting languages
I use it for scripting too. I don’t need Python as much as before nowaday.
I initially read “UNIX jungle” as “UNIX jingle” and thought I had been really missing out!
You have, look up the SuSE songs.
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!
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
A shell script can be much more agile, potent, and concise, depending on the use case.
E.g. if you want to make a facade (wrapper) around a program, that’s much cleaner in
$SHELL. All you’re doing is checking which keyword/command the user wanted, and then executing the commands associated with what you want to achieve, like maybe displaying a notification and updating a global environment variable or something.Executing a bunch of commands and chaining their output together in python is surely much more cumbersome than just typing them out next to each other separated by a pipe character. It’s higher-level. 👍
If it’s just text in text out though, sure, mostly equivalent, but for me this is rarely the use case for a script.
I’m not anti bash or fish, I’ve written in both just this week, but if we’re talking about readability/syntax as this post is about, and you want an alternative to bash, I’d say python is a more natural alternative. Fish syntax is still fairly ugly compared to most programming languages in my opinion.
Different strokes for different folks I suppose.
Fish syntax is still fairly ugly compared to most programming languages in my opinion.
subprocess.run(["fd", "-t", "d", "some_query"])vs
fd -t d some_queryWhich is cleaner? Not to mention if you want to take the output from the command and pipe it into another one.
It’s not about folks with weird opinions or otherwise, it’s about use cases. 🙂 I don’t think python is any more “natural” than most other imperative languages.
Fish is probably even more natural, actually, due to it being more high level and the legibility of the script is basically dependent on the naming of the commands and options and variables used within it, rather than something else, just like python. They probably have similarly legible keywords. Fish I imagine has fewer, which is a good thing for legibility. A script does a lot more with a lot less, due to the commands themselves doing so much behind the scenes. There’s a lot more boilerplate to a “proper” programming language than a scripting language.
But if you want to do something that python is better suited for, like advanced data processing or number crunching, or writing a whole application, then I would say that would be the better choice. It’s not about preference for me when it comes to python vs fish, it’s about the right tool for the job. But if we’re talking about bash vs fish, then I’m picking fish purely by preference. 👍
I love fish but sadly it has no proper equivalent of
set -eas far as I know.; or return;in every line is not a solution.I’ve been meaning to check out
fish. Thanks for the reminder!Happy adventuring! ✨
It’s the default on CachyOS and I’ve been enjoying it. I typically use zsh.
Yeah I also went bash -> zsh -> fish. Zsh was just too complicated to configure for my taste. Couldn’t do it, apart from copy pasting stuff I didn’t understand myself, and that just didn’t sit right.
I switched to fish a while back, but haven’t learned how to script in it yet. Sounds like I should learn
Give it a shot after reading through the manual! (Extremely short compared to bash’s!) It’s a joy in my opinion. ☺️👌
I wish I could but since I use bash at work (often on embedded systems so no custom scripts or anything that isn’t source code) I just don’t want to go back and forth between the two.
Yeah, using one tool and then another one can be confusing at times. 😅
every control structure should end in the backwards spelling of how they started
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…
AI does decently enough on scripting languages if you spell it out enough for it lol, but IMO it tends to not do so well when it comes to compiled languages
I’ve tried Python with VScode Copilot (Claude) and it did pretty good
That’s because scripted languages are more forgiving in general.
I was chalking it up to some scripting languages just tending to be more popular (like python) and thus having more training data for them to draw from
But that’s a good point too lol
Both can be true, Python does have a lot of examples floating online.
Yeah I tried that, Claude with some C code. Unfortunately the Ai only took me from point A to point A. And it only took a few hours :D
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
No, Makefile syntax is more extreme.
Sure, but bash is more relatable, I think
I find
Makefileisn’t too bad, as long as I can stay away fromautomakeandautoreconf.I swapped from Make to Just: https://github.com/casey/just
Way better, IMO. Super simple logic, just as flexible.
Unironically love powershell
For a defacto windows admin my Powershell skills are…embarrassing lol but I’m getting there!
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 withend? 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.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" doneThe
doanddoneserve 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/donecase/esacare 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 pipefailOr 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
-xthat can be very useful for debugging as it shows a trace of every command and result as it is executed.set -euo pipefailFun fact, if you’re forced to write against POSIX shell, you aren’t allowed to use these options, since they’re not a thing, which is (part of) the reason why for example Google doesn’t allow any shell language but bash, lol.
Btw, all three set options given above are included in POSIX since 2024: https://pubs.opengroup.org/onlinepubs/9799919799/
Ooh, you’re totally right!! I forgot about that since it’s not in the older versions.
I can only remember this because I initially didn’t learn about
xargs— so any time I need to loop over something I tend to usefor var in $(cmd)instead ofcmd | xargs. It’s more verbose but somewhat more flexible IMHO.So I run loops a lot on the command line, not just in shell scripts.
It seems like it does stuff differently for the sake of it being different.
It’s more like bash did it one way and everyone who came after decided that was terrible and should be done a different way (for good reason).
Looking right at you -eq and your weird ass syntax
if [[ $x -eq $y ]]That was the point where I closed the bash tutorial I was on, and decided to just use python and
subprocess.run()-eq
Yeah, like infix, so between operands, but dashed like a flag so should come before arguments. Very odd.
You better not look at powershell in that case :p
Me with powershell. I’ll write a pretty complex script, not write powershell for 3 months, come back and have to completely relearn it.
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
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.
Yeah. The best way to write any
bashscript is:apt/yum install PowerShell; pwsh script.ps1


















