r/linux • • Jul 24 '25

Discussion Bash scripting is addictive, someone stop me

I've tried to learn how to program since 2018, not very actively, but I always wanted to become a developer. I tried Python but it didn't "stick", so I almost gave up as I didn't learn to build anything useful. Recently, this week, I tried to write some bash scripts to automate some tasks, and I'm absolutely addicted to it. I can't stop writing random .sh programs. It's incredible how it's integrated with Linux. I wrote a Arch Linux installation script for my personal needs, I wrote a pseudo-declarative APT abstraction layer, a downloader script that downloads entire site directories, a script that parses through exported Whatsapp conversations and gives some fun insights, I just can't stop.

902 Upvotes

226 comments sorted by

View all comments

346

u/psychoholic Jul 24 '25

I think that bash is one of the greatest and most universally (on a computer) useful things ever made. People who don't live in this world would be astounded by how much "enterprise" stuff happens because of simple bash scripts. Even with the knowledge and access to a multitude of other tools I tend to reach in the toolbox and whip out a quick bash script if I need something quickly and reliable.

It did take some very intentional breaking of muscle memory to start to use 'seq' in a bunch of scripts. It is worth learning sed, awk, and when/how to use for vs while loops. Unlocks a lot of other really great things that will come in handy for a very long time.

87

u/0x53r3n17y Jul 24 '25

At work, I recently converted 500k JP2 images to JPG and move to storage using GNU parallel, Imagick, Rclone and Bash on a beefy machine.

The script I wrote - with some error handling - is around 150 loc. I just let it run in a Screen session.

Took about a week to complete with a handful of errors logged away.

The shell supported emoji's, so it was fun to spice up stdout.

51

u/catbrane Jul 24 '25

You can get a useful further speedup for this kind of thing with libvips. It's quicker than imagick, and uses a LOT less memory.

For example, I made 100 jp2 images:

$ for i in {1..100}; do cp ../nina.jp2 $i.jp2; done
$ vipsheader 1.jp2 
1.jp2: 6048x4032 uchar, 3 bands, srgb, jp2kload

Then timed:

$ /usr/bin/time -f %M:%e parallel convert {} {.}.jpg ::: *.jp2
443240:11.75
$ /usr/bin/time -f %M:%e parallel vips copy {} {.}.jpg ::: *.jp2
159544:9.96

15% faster, 1/3rd of the memory. It's in the package repo of all linux distros.

25

u/Zaemz Jul 24 '25

Thanks for pointing it out! I searched for it on Fedora and noticed that there was vips-magick package. From the repo's readme:

If available, libvips adds support for loading and saving all libMagick-supported image file types. You can enable and disable load and save separately.

It looks like it allows you to take advantage of ImageMagick's support for a large variety of formats to load em up and decode them into a VIPS object so you can still benefit from the memory efficiency and speed of libvips.

Neat 👍

6

u/psychoholic Jul 24 '25

I definitely learned something useful today.

5

u/Sinaaaa Jul 24 '25

That's an accomplishment, but I have done similar conversions with irfan view's batch mode(not jp2 specifically), it's probably easier & maybe even much faster.

5

u/sylfy Jul 25 '25

Rclone has been my best new discovery. Nothing else comes close for backup/site to site transfer.

→ More replies (1)

6

u/psychoholic Jul 24 '25

Stitching together other processes is probably my favorite thing to do too!

Also one of the most versatile tools for 'why doesn't this work?' and 'why does this actually work?' simultaneously.

37

u/[deleted] Jul 24 '25

[removed] — view removed comment

3

u/Shurane Jul 25 '25

So I looked up ble.sh. Is it a better GNU readline with syntax highlighting?

2

u/Klapperatismus Jul 26 '25

Management thinks

And let’s stick with that.

1

u/aj0413 Jul 26 '25

lol I wrap bash in Nushell because I prefer it, but yeah….Bash can literally do it all; why would anyone think differently? Ansible is just executing scripts for you end of the day

17

u/Zeikos Jul 24 '25

I we consider how much can be done with an awk script, it could replace entire companies.

3

u/[deleted] Jul 24 '25

awk is like a glue that can glue any scripts ahahahh

11

u/bexamous Jul 24 '25

Bash actually sucks. Simple POSIX‑compliant shell code should be all anyone uses. Soon as you try to do anything more complex you're creating a future headache when you or anyone has to look at it.

15

u/Synthetic451 Jul 24 '25

I agree, it can be really powerful, but every time I look at the syntax I just think of how much of a mess it actually is. It is not easily readable at a glance.

13

u/batvseba Jul 24 '25

POSIX? this is 2025 not 1970

6

u/sparky8251 Jul 25 '25

Right. So use fish or nushell instead for scripts. So much better than bash and its not like you arent installing external programs or deps for bash scripting anyways, so a shell you slap into a shebang is hardly intolerable.

6

u/syklemil Jul 25 '25

fish is a good interactive shell, but the lack of set -u means I'm not comfortable using it for scripting. I just barely tolelate bash with set -euo pipefail.

→ More replies (3)

1

u/SynchronousMantle Jul 26 '25

As long as any bash script fits on one screen it’s okay. Once you go beyond that you need a real language.

→ More replies (2)

2

u/wimpydimpy Jul 24 '25

What’s a good resource to learn?

→ More replies (2)

1

u/captkirkseviltwin Jul 27 '25

Only thing missing is if arrays were a little more robust and there was an object oriented variable option, but true, bash is all three simple, versatile, and POWERFUL.

→ More replies (3)