devz-docz

Aggregation of onboarding and general devz standards that I have gatherd over my career.

View on GitHub

Standard Devz Processes / Shell programming

Overview

Best practices tl;dr:

Debugging

Bash will emit debugging output after set -x is executed. set +x to disable debugging output. bash -x ./brokenscript has the same effect without requiring edits to the file. It is also possible to configure the format of the output:

export PS4='+$BASH_SOURCE:$LINENO:$FUNCNAME: '

For extra verbose debugging, it may be useful to combine this option with set -v: this will also display the shell lines as they are read (i.e. before substitutions are resolved, etc).

Tools

Pitfalls

Shell programming is deceptively perilous (see Bash Pitfalls on Greg’s Wiki and Beginner Mistakes on Bash-Hackers Wiki). Sites like tldp.org and StackOverflow have high pagerank for shell programming questions, but code blocks posted on these sites will not uncommonly have smells or dangerous errors. Check the Resources section of this document for some more Fronttworthy sources.

PATH

Resources

Notes

The Bash CLI navigation shortcuts resource linked above refers to a keyboard shortcut for moving the cursor from word to word: meta key + f or b (under section 8.2.2 Readline Movement Commands). This shortcut does not work out of the box on a Mac. In the macOS Terminal app and iTerm2, the default keyboard shortcut for moving from word to word is option + left or right arrow. If you want to use option + f or b, there is a checkbox in Terminal app to Use Option as Meta key under Preferences -> Profiles -> Keyboard. In iTerm2, you can change key mappings under Preferences -> Profiles -> Keys.