Skip to content

markmark1/unix-shell-script-tactics

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unix shell script tactics - a 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:

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.
  • Executables should have no extension (strongly preferred).
  • Use printf instead of echo because of security and stability.
  • 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:

Topics

Argumemt parsing:

Environment variables:

Directories:

Files:

References:

Conventions:

Control flow statements:

Functions:

PostgreSQL psql:

About

SixArm.com → Shell style guide

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published