Follow

My second blog post about my attempts to learn scripting. I'm gradually getting used the basic syntax with it tests, command substitution, quotes and brackets. And I can make something actually useful, resizing a photo.

homehack.nl/humble-start-of-ba

@ericbuijs Nice stuff! Maybe it would be better to do if [ $answer != "Y" ] (or whatever the correct syntax is) since now it will overwrite if you hit another key, which is not ideal

@Matter Thanks for the tip. Still got a lot to learn but it certainly is fun.

@ericbuijs that's a good start with the conditionals and command line arguments. There's also the ability to write functions, use variables, etc. But you are doing exactly what you can to learn bash, taking something you discovered and practice with it. It's that experience with everything that makes it easier to absorb.

@lee8oi Thanks Lee, working on loops now. Changing filenames in bulk seems like a very handy script to me.

@ericbuijs That's the best kind to learn from. The handy ones. And there's almost always a way to make them a little better. That's more fun to be had learning :)

@ericbuijs Once you feel the power of what a quick script can do you will become addicted.
I fear it may already be too late for you Eric! :-)
After over 20 years of scripting, you can imagine what /home/gemlog/bin looks like...

@gemlog I've been putting this off for far too long but you're right it's becoming addictive to get the script running properly :D.

@ericbuijs Once you do it for one, the next move will be to read in a directory and iterate over it. At that point you have the swiss army chainsaw of all 'templates'.
Many scripts I have read in a list of <stuff> and do <something> to each.
You will see: they will begin to breed and grow!
Maybe you want to watermark each pic too? IM can do that.
Maybe you have a bunch of podcasts with intros and extros you've heard too often? ffmpeg can crop them. Convert videos, fix file names...

@ericbuijs check out the bash scripting stuff on #hpr. Very useful stuff from Dave and company.

http://hackerpublicradio.org/series.php?id=42

@cobra2 @ericbuijs Thanks for the reference. I hope the Bash shows on #hpr are helpful.

@cobra2 That's a great show. I've put the RSS feed on my Friendica account and added it to my Squeezebox server so I can listen to it anywhere in my house.

@ericbuijs submit a show sometime. It's people like us that keep content coming.

@ericbuijs
Nice first steps!
Something you'll probably find useful to look into next, is handling commandline arguments/options (-h, --help etc). This article by Drew Stokes has an interesting approach for that, aside from mentioning getopt(s), and also the comments have some valuable tips: medium.com/@Drew_Stokes/bash-a

While I usually grab Ruby because it feels quicker to whip something up, I now more often try Bash instead for portability.

Sign in to participate in the conversation
Fosstodon

Fosstodon is a Mastodon instance that is open to anyone who is interested in technology; particularly free & open source software.