- cross-posted to:
- programmerhumor@lemmy.ml
- cross-posted to:
- programmerhumor@lemmy.ml
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.
I use it for scripting too. I don’t need Python as much as before nowaday.
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 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!
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.
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.
It’s the default on CachyOS and I’ve been enjoying it. I typically use zsh.
I love fish but sadly it has no proper equivalent of
set -e
as far as I know.|| return;
in every line is not a solution.I switched to fish a while back, but haven’t learned how to script in it yet. Sounds like I should learn
I’ve been meaning to check out
fish
. Thanks for the reminder!Happy adventuring! ✨
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.
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.
Until the magic incantations you don’t bother to understand don’t actually do what you think they’re doing.
Sounds like a problem for future me. That guy hates me lol
Yeah fuck that guy
I wonder if there’s a chance of getting
rm -rf /*
or zip bombs. Those are definitely in the training data at least.The classic
rm -rf $ENV/home
where$ENV
can be empty or contain spaces is definitely going to hit someone one day
In fairness, this also happens to me when I write the bash script myself 😂
Yes, I have never wrote a piece of code that didn’t do what I thought it would before LLMs, no sir.
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.
Incredibly true for me these days. But don’t fret, shellcheck and tldp.org is all you need. And maybe that one stackoverflow answer about how to get the running script’s directory
When I was finishing of my degree at Uni I actually spent a couple of months as an auxiliary teacher giving professional training in Unix, which included teaching people shell script.
Nowadays (granted, almost 3 decades later), I remember almost nothing of shell scripting, even though I’ve stayed on the Technical Career Track doing mostly Programming since.
So that joke is very much me irl.
Bash substitution is regex-level wizardry.
Slapping a $ before an environment variable name is “wizardry?”
interns be interning
Not quite that, but more the
${variable##.*}
sort of thing.Right, so that’s just the string manipulation functions. I already posted a link to the bible for this following a different reply to the same comment to which you replied.
Back then, a pain in the ass. Nowadays, I just let an AI handle that. I used this crap for years and years and still cannot remember, which symbols you need in which order. And why should I remember? I’m not the computer. The computer should know, not me.
Nope, the whole
{variable/regex/replacement}
syntaxAll the string manipulation functions are easy: https://tldp.org/LDP/abs/html/string-manipulation.html
This one is my bookmark
Every time I have to do this I always go here. I can never remember the prefix suffix parts next time I do parameter substitution.
Regex
This is one of the best uses for LLM’s imo. They do all my regex for me.
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.
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.
I give you that, true. I wish vim had PCRE
There is the “very magic” mode for vim regexes. It’s not the exact PCRE syntax, but it’s pretty close. You only need to add \v before the expression to use it. There is no permanent mode / option though. (I think you can remap the commands, like / to /\v)
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.
No. Learn it properly once and you’re good. Also it’s super handy in vim.
interns gonna intern
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.
twitch
Don’t let the gatekeepers keep you out. This site helps.
Chatgpt helps even more
I know that LLMs are probably very helpful for people who are just getting started, but you will never understand it if you can’t grasp the fundamentals. Don’t let “AI” make you lazy. If you do use LLMs make sure you understand the output it’s giving you enough to replicate it yourself.
This may not be applicable to you specifically, but I think this is nice info to have here for others.
I feel same with regex…
VLOOKUP. Every time. Also Catan Cities and Knights.
to be honest I agree and thought we would be using something more intuitive by now
Everything is text! And different programs output in different styles. And certain programs can only read certain styles. And certain programs can only convert from some into others. And don’t get me started on
IFS
.I think the cool kids are using Nu now
This is why I finally switched to nushell.
I love Nushell
I’d been considering it for awhile, but thought it wasn’t worth the trouble of switching until I realized just how often I do things the tedious manual way because writing a bash script to do it is so arcane
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)
Remember to make the .sh file executable with chmod +x
I try to remember to use man when learning a new command/program. And I almost always half-ass it and press the search button immediately to find whatever flag i need.
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 ]]
You better not look at powershell in that case :p
-eq
Yeah, like infix, so between operands, but dashed like a flag so should come before arguments. Very odd.
That was the point where I closed the bash tutorial I was on, and decided to just use python and
subprocess.run()
I’ve switched to nutshell imo. Bash is in need of a replacement
No, Makefile syntax is more extreme.
I swapped from Make to Just: https://github.com/casey/just
Way better, IMO. Super simple logic, just as flexible.
Sure, but bash is more relatable, I think
I find
Makefile
isn’t too bad, as long as I can stay away fromautomake
andautoreconf
.