Skip to main content

Bash Shell Scripting Part 8 – Control Structures (If)

Bash Shell ScriptingOne thing that you will probably realize early on when planning out a shell script, is that you cannot possibly anticipate every single outcome.

The best that you can do is plan for the outcomes and possibilities that you can anticipate, and funnel the remainders into a catch-all.

This is made possible by the most common control structure: the if statement.

Read More

Bash Shell Scripting Part 7 – Control Structures (Intro)

Bash Shell ScriptingI like to think of programming (scripting) as a series of decisions made based on a system of reasoning — a process otherwise known as logic.

Logic is something that we all make use of every day when we decide what to do, and how and in what order to do it. In such cases, logic is usually an unconscious process based on actions and consequences.

We employ more conscious forms of logic when solving problems and deliberately working through processes to achieve a desired result.

Programming (scripting) employs a very deliberate form of logic, brought to pass through the use of control structures, which are dependent on various conditions presented to them.

In life and programming alike, results can be controlled by whether or not conditions are met, and how and to what degree they are met. But I gotta tell you, it’s a lot easier to anticipate and control conditions in a program than it is in real life!

Read More

Bash Shell Scripting Part 6 – User Input

Bash Shell ScriptingIn order to handle shell script arguments, it is needful to know that the arguments are required.

It can be a big hassle for people running the script to figure out what exactly is required to be able to run it.

In fact, in many cases — such as those where the user does not know how to write and thus read the bash script code — using a script correctly can be just about impossible.

To solve this problem, there is a little something called user input, which allows a script to be written in such a way as to prompt the user for input, wait until it is received, and carry on with execution.

When this solution is in use, any further issues usually boil down to PEBCAK*.

Read More

Bash Shell Scripting Part 5 – Arguments

Bash Shell ScriptingArguments bring up thoughts of heated exchanges, differences of opinion, and persuasive reasoning — unless you’re a programmer.

A programmer knows that an argument is actually a value or data that is passed to a function or a program when it is called.

In fact, if you’ve even so much as used the command line, and typed in various commands, you have no doubt used arguments with those commands already.

In bash shell scripts, arguments can be added to the command line when a script is executed, and those arguments can be read/accessed within the script.

Special variables are used in shell scripts to access command line arguments, so to begin with, let’s take a look at the special variables available.

Read More

Bash Shell Scripting Part 4 – Variables

Bash Shell ScriptingNow that we have successfully created and executed a shell script, it’s time to start building on the functionality available to shell scripts.

The topics to come may sound heavy, but they’re actually very cool, and can serve as a basic primer for anyone interested in learning programming.

For anyone not interested in programming, the logic that can be applied in shell scripting is none-the-less a useful skill to have.

The first of these, that I found downright enthralling (when I first began programming years ago), are variables.

Read More

All About the Dot Slash Issue

Dot Slash Command LineIn an upcoming series I’m going to start exploring the basics of shell scripting (writing your own little programs that run from the command line and make things happen).

In the meantime — with not a little prompting from my Dad — I’ve decided to explore the dot slash issue.

I call it an issue, but really it’s just two keystrokes resulting in two characters that get placed before shell scripts to execute said shell scripts.

Read More