unix-shell-script-tactics
Unix shell script tactics - best practices style guide
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (10.9%) to scientific vocabulary
Keywords
Repository
Unix shell script tactics - best practices style guide
Basic Info
Statistics
- Stars: 345
- Watchers: 8
- Forks: 18
- Open Issues: 0
- Releases: 0
Topics
Metadata Files
README.md
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
setflags such asset -euf - Print output with
printfnotecho - 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 keywordsource - Version name: use semantic versioning
- Help: use a function and HERE document
- Date & 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
mktempinstead oftempfileet. al.
Demo:
Topics
Argument parsing:
Environment variables:
Directories:
- Script directory: use realpath or cd
- Log directory: use $LOG_HOME
- Data directory: use $XDGDATAHOME
- Cache directory: use $XDGCACHEHOME
- Configuration directory: use $XDGCONFIGHOME
- Runtime directory: use $XDGRUNTIMEHOME
- Temporary directory:: use
mktemp
Files:
- Temporary file using
mktempandtrap - Find files with filter for permission denied
- Find files with special characters
- Find files with readable permissions
- Find files with executable, perm, test, exec
References:
- Writing safe shell scripts
- Richs sh (POSIX shell) tricks
- Google Shell Script Style Guide
- Filenames and Pathnames in Shell: How to do it Correctly
- Standard Command-Line Options
- How to do things safely in bash
- pure sh bible & pure bash bible
Conventions:
- Program name using a string or basename
- Git top level directory using rev-parse
- Functions: out, err, die, big, log, now, sec, zid, cmd, etc.
- Assert functions: assertempty, assertequal, assert_match
- sec() function portability
Control flow statements:
Functions:
Command snippets:
Compatibilities:
PostgreSQL psql:
Owner
- Name: SixArm
- Login: SixArm
- Kind: organization
- Email: sixarm@sixarm.com
- Location: San Francisco
- Website: http://sixarm.com
- Twitter: sixarm
- Repositories: 580
- Profile: https://github.com/SixArm
SixArm Software
Citation (CITATION.cff)
cff-version: 1.2.0
title: Unix shell script tactics - best practices style guide
message: >-
If you use this work and you want to cite it,
then you can use the metadata from this file.
type: software
authors:
- given-names: Joel Parker
family-names: Henderson
email: joel@joelparkerhenderson.com
affiliation: joelparkerhenderson.com
orcid: 'https://orcid.org/0009-0000-4681-282X'
identifiers:
- type: url
value: 'https://github.com/SixArm/unix-shell-script-tactics'
description: Unix shell script tactics - best practices style guide
repository-code: 'https://github.com/SixArm/unix-shell-script-tactics'
abstract: >-
Unix shell script tactics - best practices style guide
license: See license file
GitHub Events
Total
- Watch event: 9
- Push event: 1
Last Year
- Watch event: 9
- Push event: 1
Committers
Last synced: 9 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Joel Parker Henderson | j****l@j****m | 140 |
| Tom | 7****e | 1 |
| Julian Orchard | h****o@j****k | 1 |
| Edwin Kofler | e****n@k****v | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 9 months ago
All Time
- Total issues: 1
- Total pull requests: 3
- Average time to close issues: about 4 hours
- Average time to close pull requests: about 16 hours
- Total issue authors: 1
- Total pull request authors: 3
- Average comments per issue: 1.0
- Average comments per pull request: 1.0
- Merged pull requests: 3
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- tmzane (1)
- kseistrup (1)
Pull Request Authors
- julianorchard (2)
- tmzane (1)
- hyperupcall (1)