ba.sh: A minimal pattern for organising bash code

“Simplicity is the ultimate sophistication.” (c) Leonardo da Vinci

When you hear “bash OOP framework”, what comes to mind? Probably complexity, overhead, fighting the language. But what if it didn’t have to be that way? If you’ve written bash scripts for any length of time, you know how it can go. It starts simple: a few commands in a file. Then you add a function. Then another. Then some variables. Before you know it, you have 500 lines of tangled code where everything can access everything, functions have names you don’t remember, and you’re scared to change anything because you don’t know what might break. [Read More]

Calculating netmask in bash

Masks were meant to be used for a reason and not to hide behind. (c) Anthony T. Hincks

A subnet mask is a set of bits that determines how many bits are used to specify the subnet address and how many are used to specify the computer address within that subnet. It’s more common to see a subnet mask in decimal notation, but it’s actually represented in binary. If you understand how a subnet address and a computer address within that subnet are represented, you can easily determine the subnet address and subnet mask from the computer address and subnet mask, as follows: <subnet-address>/<number-of-bits> [Read More]

Script that works in Windows and Linux

There is no neat distinction between operating system software and the software that runs on top of it (c) Jim Allchin

When you work with computers that run different operating systems, such as Linux and Windows, then you probably have some similar tasks you execute in both of them. And for each operating system you write a separate script. Or may be you write programs in Java and for each operating system you have a script to set up an environment (sh-script or cmd-script). If you need to do basically the same in Windows and in Linux, you can write only one script, that will work in both operating systems. [Read More]