Snapshot của progrium/bashstyle: 1.8k★. Let's do Bash right!
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
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
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/progrium/bashstyle là nguồn chính thức.
progrium/bashstyle có bao nhiêu sao?
progrium/bashstyle có 1.8k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/progrium/bashstyle. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
progrium/bashstyle có phải mã nguồn mở không?
TopGit chưa ghi nhận license cho progrium/bashstyle. Phần lớn repo public trên GitHub là mã nguồn mở, nhưng điều khoản khác nhau từng repo — mở file LICENSE để xác nhận.
progrium/bashstyle còn đang phát triển không?
Commit gần nhất trên progrium/bashstyle là 5.5 năm trước (theo timestamp GitHub). Repo có 95 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
progrium/bashstyle là gì?
progrium/bashstyle (progrium/bashstyle) là dự án đa ngôn ngữ trên GitHub. Theo mô tả gốc: Let's do Bash right!
progrium/bashstyle viết bằng ngôn ngữ gì?
Dữ liệu TopGit chưa ghi nhận ngôn ngữ chính cho progrium/bashstyle. Xem danh sách file trên GitHub để biết chi tiết.
Đọc đầy đủ README ở tab phía trên.
bashstyle có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về bashstyle.