Learning more Bash by writing a script deploy my Jekyll site

Although enamored by its utility, I have written little serious Bash in my career as a programmer. That changed, recently, when I wrote a Bash script that deploys my website.

As a programmer of other scripting languages, Bash can seem as inviting as an old-growth forest – thick and wicked and arcane. That same abstrusity, though, acts as an enticement.

I admit it: this Hanzel-and-Gretel allure drove me to write my deployment script as much as Bash’s portability and straight-forward access to system utilities.

Below are a few things I learend along the way.

Standard input, output, and error

My vague understanding of standard input, output, and error was clarified. Effectively, each is a file handle to which processes have access. You can redirect standard output and error separately. For example, this allows you to redirect stdout to a file and print stderror to a terminal.

Exit codes

When a process finishes, or exits, it outputs an exit code as an integer. Generically, any code other than 0 means there was an error. Exit codes and their meanings can often be found in man pages for the command in question. Depending on where you read, this code might be refenced as an exit value or exit status.

Thoughtful error code use allows more robust fault-tolerance in scripts. By adding exit codes, you improve reusability of scripts. As desires or requirements grow, composing small scripts becomes a quick way to achieve outcomes fast.

Date and time

Two useful bash commands related to date and time are, well, date and time.

The date command outputs the current system date and time, which proved handy for time-stamping logs.

Unlike you may suspect, time does not report the current time. The time command reports how long a command takes to complete. This is a useful utility to keep on hand for quick, simple profiling.

Out of the woods

Upon reflection, Bash remains a thorny language. The wide-array of versatile, stable Unix utilities, though, make it an attractive language for composing simple automation tools like my deployment script.

About Work Blog Hire Now