Getting started with bash scripts



@kc1di :-

Good one, Dave.

The way I taught myself Bash scripting may not work for anyone else, but I started off by automating very simple functions - "Hello World" was one of the first, it's true.

I did a lot of research. I studied tutorials on many of the Linux blogs. Some of these had examples for various things, with step-by-step instructions. I visited a LOT of online manpages, to get a better idea of how various functions should be implemented, along with their available options and what these did.

I quite unashamedly admit that I also extracted packages created by many other Puppians, to study how they, too, went about things.....and I spent hour after hour just trying stuff out in the terminal. This is probably the most salient point; practice, practice, and MORE practice.

As you get more confidence you start to string things together, so that conditions in one place will lead to actions in another. This is probably the basis of all programming; you know what you want to do and, little by little, with lots of experimentation, you discover the most efficient/effective ways of scripting to achieve your desired outcome.

Bash scripting is an ongoing process; it's always interesting to see what CAN be done, and you're always learning. In my case, many functions get their own dedicated scripts.....following the general Linux/Unix philosophy; do ONE thing, but do it as well as possible. Then a main, or "master" script, calls all these scripts as & when required and strings everything together to deliver the results I'm after. Perhaps not a very good technique.....but it helps me to keep my scripts simple. The more complex your scripts grow, the harder troubleshooting becomes as & when things inevitably misbehave.

(I'm not after making a career outta this stuff.....those days are behind me now, thank God. For me, this is a hobby; it's something I enjoy, and hails all the way back to the very first simple "Hangman" program I wrote on a Commodore 64 in 1983!)

~~~~~~~~~~~~~~~~~~~~~

Scripting is like learning any language; different programming languages have their own distinct nuances, and implement things in different ways. But you can probably achieve the same outcome in a dozen or more ways; you find what works for you.....and you "play" with it!

It's good fun. There IS no "right" or "wrong" way to script; as stated above, over time - and as your confidence grows - you will sooner or later develop techniques that work for YOU. And never be afraid to try new things; it's quite surprising - and you WILL discover this - how often the same snippets of code show up in different places.

Just play around; experiment.....and above all, ENJOY. Learn at your own pace; it's not a competition, to see who can learn the fastest. It doesn't work like that.

Results are what count....


Mike. ;)
 
Last edited:
Scripting is like learning any language; different programming languages have their own distinct nuances, and implement things in different ways.
The thing that's neat about bash scripting is you have thousands of binary programs you can work with, and making practical scripts is often simpler than doing the same thing in other scripting languages because of that.
 
Last edited:
Off-topic:

Pemaquid appears to have taken some damage. We had high winds but mostly snow that was followed by rain. The winds weren't high enough to do any major damage.

The coast got screwed, I guess.
 
i'm just glad i learned what Permaquid is today! Sad, it could have been a more boring building.

Still off-topic...

If you go to Pemaquid Point, the lighthouse, turn around and look up. You'll see a hill.

Climb to the top of the hill and you'll find a restaurant that has the catch of the day among other delicious things to put in your facehole. I forget the name, but it's one of the best restaurants I've ever been to. Sadly, it's nowhere near where I live. I haven't been there in years.

At least the last storm wasn't as deadly as the storm before it (as far as I know).

Anyhow, to say something on topic...

If you're going to learn Bash scripting, you should probably learn to use ShellCheck.

 

Members online


Latest posts

Top