DEV Community

Thomas H Jones II
Thomas H Jones II

Posted on • Originally published at thjones2.blogspot.com on

Why I Default to The Old Ways

I work with a growing team of automation engineers. Most are purely dev types. Those that have lived in the Operations world, at all, skew heavily towards Windows or only had to very lightly deal with UNIX or Linux.

I, on the other hand, have been using UNIX flavors since 1989. My first Linux system was the result of downloading a distribution from the MIT mirrors in 1992. Result, I have a lot of old habits (seriously: some of my habits are older than some of my teammates). And, because I've had to get deep into the weeds with all of those operating systems many, many, many times, over the years, those habits are pretty entrenched ("learned with blood" and all that rot).

A year or so ago, I'd submitted a PR that included some regex-heavy shell scripts. The person that reviewed the PR had asked "why are you using [<SPACE><TAB>]* in your regexes rather than just \s?". At the time, I think my response was a semi-glib, "A) old habits die hard; and, B) I know that the former method always works".

That said, I am a lazy-typist. Typing "\s" is a lot fewer keystrokes than is "[<SPACE><TAB>]*". Similarly, "\s" takes up a lot less in the way of column-width than does "[<SPACE><TAB>]*" (and I/we generally like to code to fairly standard page-widths). So, for both laziness reasons and column-conservation reasons, I started to move more towards using "\s" and away from using "[<SPACE><TAB>]*". I think in the last 12 months, I've moved almost exclusively to "\s".

Today, that move bit me in the ass. Well, yesterday, actually, because that's when I started receiving reports that the tool I'd authored on EL7 wasn't working when installed/used on EL6. Ultimately, I traced the problem to an awk invocation. Specifically, I had a chunk of code (filtering DNS output) that looked like:

awk '/\sIN SRV\s/{ printf("%s;%s\n",$7,$8)}'

Which worked a treat on EL7 but on EL6, "not so much." When I altered it to the older-style invocation:

awk '/[]\*IN[]\*SRV[]\*/{ printf("%s;%s\n",$7,$8)}'

It worked fine on both EL7 and EL6. Turns out the ancient version of awk (3.1.7) on EL6 didn't know how to properly interpret the "\s" token. Oddly (my recollection from writing other tooling) is that EL6's version of grep understands the "\s" token just fine.

When I Slacked the person I'd had the original conversation with a link to the PR with a "see: this is why" note, he replied, "oh: I never really used awk, so never ran into it".

Top comments (4)

Collapse
 
moopet profile image
Ben Sinclair

I see this sort of thing too. I see it a lot with people newer to the shell, who use zsh on a Mac (and use oh-my-zsh like people use jQuery). They run a cropper when their simple scripts have to work inside a container running a different OS. Particularly things like sed -i.

Collapse
 
ferricoxide profile image
Thomas H Jones II

It took me forever to switch from POSIX-Shell/KSH to BASH because, up until the late-aughts, BASH wasn't a standard part of the OSes I was administering at the time. Really, it wasn't until my customers and employers started to use VMware to "virtualize all the things" – and the accompanying switch from legacy UNIX solutions to Linux — that I made the switch. Even though KSH and BASH script similarly and and have a lot of overlaps in interactive functionalities, I tend to be a "power user" ...which tends to magnify those slight differences.

It used to really gripe me during that period when I'd ask junior team members "why are you using an add-on shell" and, invariably, the response was "arrow-history" or "tab-completion". I mean, there were a lot of good reasons to prefer BASH, but, at the time, those two features were pretty standard (if you knew the shell-options to enable them), so, those features didn't seem to be worth running into scenarios where you logged in to fix a system but were handicapped because the main tool in your "SA's toolbox" was missing. :p

Collapse
 
moopet profile image
Ben Sinclair

Whenever I see someone go on about how zsh is the new cool, I ask them what they like about it. Almost everything they say is either from an add-on (like oh-my-zsh) or also available in every other shell you're likely to use.

The things that are different between shells are not thing they ever do.

I'm in the habit of making every script POSIX if there's not a good reason. I'm going to be doing a workshop on command-line skills at my office soon and want to go full-on YAGNI.

Thread Thread
 
ferricoxide profile image
Thomas H Jones II • Edited

Won't get any arguments from this curmudgeon (get off my lawn!).

:)