1529
top 50 comments
sorted by: hot top controversial new old
[-] JTskulk@lemmy.world 12 points 15 hours 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

[-] PieMePlenty@lemmy.world 3 points 13 hours ago

My google history hits for powershell for loop is is in the dozens.

[-] LeninOnAPrayer@lemm.ee 4 points 16 hours ago* (last edited 16 hours ago)

The sad thing is that even chatgpt can't program in bash. I just want a simple script and every single time it just doesn't work. I always just end up saying "write this in python instead".

[-] PrettyFlyForAFatGuy@feddit.uk 23 points 1 day ago

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

I've coded in bash for a while

[-] jkercher@programming.dev 6 points 19 hours 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.

[-] 6mementomorib 9 points 21 hours ago

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 4 points 19 hours 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.

[-] MajorHavoc@programming.dev 4 points 21 hours ago

Yeah. The best way to write any bash script is:

apt/yum install PowerShell; pwsh script.ps1

[-] 0x0@lemmy.dbzer0.com 56 points 1 day ago

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 23 hours 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)
[-] victorz@lemmy.world 28 points 1 day ago

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 22 hours ago

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

[-] victorz@lemmy.world 3 points 14 hours ago* (last edited 14 hours ago)

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.

[-] UndercoverUlrikHD@programming.dev 1 points 13 hours ago

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.

[-] victorz@lemmy.world 1 points 8 hours ago

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_query

Which 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. ๐Ÿ‘

[-] LeninOnAPrayer@lemm.ee 2 points 16 hours ago

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.

[-] victorz@lemmy.world 1 points 14 hours ago

Yeah, using one tool and then another one can be confusing at times. ๐Ÿ˜…

[-] raldone01@lemmy.world 6 points 22 hours ago* (last edited 9 hours ago)

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.

[-] victorz@lemmy.world 3 points 14 hours ago

Some good discussion here.

Also some good points here.

BTW, the or and and keywords are super neat.

[-] JackbyDev@programming.dev 2 points 20 hours ago

It's the default on CachyOS and I've been enjoying it. I typically use zsh.

[-] victorz@lemmy.world 1 points 15 hours ago

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.

load more comments (4 replies)
[-] baratheon@lemmy.world 9 points 23 hours ago

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

[-] JackbyDev@programming.dev 5 points 20 hours ago

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.

[-] QuazarOmega@lemy.lol 3 points 21 hours ago

I think the cool kids are using Nu now

[-] zarathustra0@lemmy.world 10 points 1 day ago

No, Makefile syntax is more extreme.

[-] spicystraw@lemmy.world 6 points 23 hours ago

Sure, but bash is more relatable, I think

[-] Xanza@lemm.ee 2 points 19 hours ago

I swapped from Make to Just: https://github.com/casey/just

Way better, IMO. Super simple logic, just as flexible.

load more comments (1 replies)
[-] conditional_soup@lemm.ee 112 points 1 day ago* (last edited 1 day ago)

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.

[-] LeninOnAPrayer@lemm.ee 1 points 16 hours ago* (last edited 16 hours ago)

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.

[-] dirtycrow@programming.dev 1 points 16 hours ago

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.

[-] kameecoding@lemmy.world 33 points 1 day ago

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

load more comments (1 replies)
[-] 9point6@lemmy.world 37 points 1 day ago

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

load more comments (17 replies)
[-] cupcakezealot 23 points 1 day ago

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

[-] grrgyle@slrpnk.net 17 points 1 day ago

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

Shame about do though.

load more comments (1 replies)
[-] shortrounddev@lemmy.world 13 points 1 day ago

Unironically love powershell

load more comments (1 replies)
load more comments
view more: next โ€บ
this post was submitted on 05 Mar 2025
1529 points (100.0% liked)

Programmer Humor

21016 readers
1242 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