progrium/bashstyle is an open-source project on GitHub with 1.8k stars. Let's do Bash right!
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
Bash is the JavaScript of systems programming. Although in some cases it's better to use a systems language like C or Go, Bash is an ideal systems language for smaller POSIX-oriented or command line tasks. Here's three quick reasons why:
It's everywhere. Like JavaScript for the web, Bash is already there ready for systems programming.
It's neutral. Unlike Ruby, Python, JavaScript, or PHP, Bash offends equally across all communities. ;)
It's made to be glue. Write complex parts in C or Go (or whatever!), and glue them together with Bash.
This document is how I write Bash and how I'd like collaborators to write Bash with me in my open source projects. It's based on a lot of experience and time collecting best practices. Most of them come from these two articles, but here integrated, slightly modified, and focusing on the most bang for buck items. Plus some new stuff!
Keep in mind this is not for general shell scripting, these are rules specifically for Bash and can take advantage of assumptions around Bash as the interpreter.
Big Rules
Always double quote variables, including subshells. No naked $ signs
This rule gets you pretty far. Read http://mywiki.wooledge.org/Quotes for details
All code goes in a function. Even if it's one function, main.
Unless a library script, you can do global script settings and call main. That's it.
Avoid global variables. Though when defining constants use readonly
Always have a main function for runnable scripts, called with main or main "$@"
If script is also usable as library, call it using [[ "$0" == "$BASH_SOURCE" ]] && main "$@"
Always use local when setting variables, unless there is reason to use declare
Exception being rare cases when you are intentionally setting a variable in an outer scope.
Variable names should be lowercase unless exported to environment.
Always use set -eo pipefail. Fail fast and be aware of exit codes.
Use || true on programs that you intentionally let exit non-zero.
Never use deprecated style. Most notably:
Define functions as myfunc() { ... }, not function myfunc { ... }
Always use [[ instead of [ or test
Never use backticks, use $( ... )
See http://wiki.bash-hackers.org/scripting/obsolete for more
variadic_func() {
local arg1="$1"; shift
local arg2="$1"; shift
local rest="$@"
# ...
}
Conditionals: Testing for exit code vs output
# Test for exit code (-q mutes output)
if grep -q 'foo' somefile; then
...
fi
# Test for output (-m1 limits to one result)
if [[ "$(grep -m1 'foo' somefile)" ]]; then
...
fi
The most recent commit recorded on progrium/bashstyle was 5.7 years ago, based on the GitHub push timestamp. The repository has 94 forks — one of the better signals of community interest.
How many stars does progrium/bashstyle have?
progrium/bashstyle has 1.8k GitHub stars — refresh the page for the live number, or check github.com/progrium/bashstyle. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
Is progrium/bashstyle open source?
TopGit's metadata for progrium/bashstyle does not record a license. Most public repositories on GitHub ARE open source, but the exact terms vary — verify by opening the LICENSE file directly.
What is progrium/bashstyle?
progrium/bashstyle (progrium/bashstyle) is a multi-language project on GitHub. From the project's own README: Let's do Bash right!
What language is progrium/bashstyle written in?
TopGit's last sync did not record a primary language for progrium/bashstyle. Open the repository on GitHub to see the full breakdown by file extension.
Where do I read more about progrium/bashstyle?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/progrium/bashstyle is the definitive source.
Read full README in the tab above.
Is bashstyle worth your time?
ChatGPT, Claude and Perplexity can all read this page. Ask one of them what it makes of bashstyle.