{"repo":"SixArm/unix-shell-script-tactics","free":true,"listed":false,"github":"https://github.com/SixArm/unix-shell-script-tactics","clone":"git clone https://github.com/SixArm/unix-shell-script-tactics.git","description":"Unix shell script tactics - best practices style guide","language":"Shell","stars":361,"topics":["shell","style-guide","unix"],"license":null,"category":"cli-tools","readme_excerpt":"Unix shell script tactics - best practices style guide This Unix shell script style guide helps us write better Unix shell script code for speed, security, stability, and portability. This guide is by SixArm.com, a software consultancy. Our customers use shell scripts within a wide variety of Unix shells, so we aim for POSIX for simple scripts. Highlights: - Aim for POSIX when possible because of portability and standardization - Protect scripts by using set flags such as set -euf - Print output with printf not echo - Trap signals and exit by using trap trap exit EXIT - Use a main() function - Run executable with no file name extension - Source with dot operator . not keyword source - Version name: use semantic versioning - Help: use a function and HERE document - Heredoc with cat not read - Date &amp; time format: use UTC and ISO8601 - Booleans: use true and false - Colors: use terminal escape codes & NO COLOR & TERM=dumb - Subshells: use parentheses $() not backticks - Trace using set -x then set +x without printing - Hunt for bugs by using ShellCheck - Fix some bugs automatically, if you want, by using Shellharden Recommendations (details of these are TODO): - Quote liberally such as \"$var\" instead of just $var , for safety. - Bulletproof scripts to handle characters such as a quote, newline, leading dash. - Enable a user to customize commands by using env vars such as ${FOO:-foo} . - Create temporary files by using mktemp instead of tempfile et. al. Demo: - Unix shell scr","default_branch":null,"files":null,"tree":[],"storefront":"/r/SixArm","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/SixArm/unix-shell-script-tactics/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}