我正在努力学习一些Bash,以便有一天可能会找到一份使用计算机的工作.
为了提高我的清晰度和门徒编写我的自学代码,我试图坚持一套一致的"指导原则".
当我推出自己的"指导方针"时,我显然会问自己:我不应该使用既定标准吗?
我找不到一个这样的"权威"参考Bash,类似于这些其他语言:
这是我自己整理的东西......但我认为,特别是作为一个初学者,我应该使用专家编写的指南,而不是试图想出我自己的指南,因为它们不会基于丰富的经验,见解,实用性,常见模式/反模式的知识等.
你可能会对这些文件的有效性提出异议,但是有些人必须喜欢网络上的这些突出的例子,就像我在上面的子弹列表中提到的那样.
################################################################################
# Coding conventions
#
# - Prefer lines of 80 characters of length or less
#
# - Perform arithmetic operations and numeric comparisons within "(( ))" blocks
# e.g. if ((42<=24+24)), ((3**3==27))
#
# - Reference variables by name, not expansion, within arithmetic evaluation
# e.g. ((i++)) rather than (($i++)), ((v+=42)) rathern than v=$(($v+42))
#
# - Prefer "[[" to "[" for conditional expressions
#
# - Prefer "[[ $s ]]" to "[[ -n $s ]]" when checking for empty strings
#
# - Document each function with at least a summary sentence. This should not
# exceed the preferred line length, be written in third person, end with a
# period and concisely describe the general utility of the function
#
# ...
# ...
# ...
#
################################################################################
Run Code Online (Sandbox Code Playgroud)
oen*_*lli 11
像往常一样谷歌是你的朋友.我从谷歌获得的最好的bash风格指南:https://google.github.io/styleguide/shell.xml
此处还有来自Chromium项目的一些额外建议:http://www.chromium.org/chromium-os/shell-style-guidelines
为了学习bash,Apple Developer Shell Scripting入门非常出色:https://developer.apple.com/library/mac/documentation/opensource/conceptual/shellscripting/Introduction/Introduction.html
使用bash风格指南是非常明智的,因为它充满了技巧和意想不到的,难以诊断的怪癖.至少如果你一直遵循相同的风格,你应该只为每个技巧一次.
koj*_*iro 10
愚蠢的一致性是小脑袋的大人物,由小政治家,哲学家和神职人员所崇拜.
- 拉尔夫沃尔多爱默生
-execdir
时,用适当的find
.null
当工具集允许避免在空白区域意外分词时使用分隔符.