END
Embedded newlines are ok too
long_string="I am an exceptionally
long string."
管道
如果一行容不下整个管道操作,那么请将整个管道操作分割成每行一个管段。
如果一行容得下整个管道操作,那么请将整个管道操作写在同一行。
否则,应该将整个管道操作分割成每行一个管段,管道操作的下一部分应该将管道符放在新行并且缩进2个空格。这适用于使用管道符’|’的合并命令链以及使用’||’和’&&’的逻辑运算链。
All fits on one line
command1 | command2
Long commands
command1 \
| command2 \
| command3 \
| command4
循环
请将 ; do , ; then 和 while , for , if 放在同一行。
shell中的循环略有不同,但是我们遵循跟声明函数时的大括号相同的原则。也就是说, ; do , ; then 应该和 if/for/while 放在同一行。 else 应该单独一行,结束语句应该单独一行并且跟开始语句垂直对齐。
例如:
for dir in ${dirs_to_cleanup}; do
if [[ -d “ d i r / {dir}/ dir/{ORACLE_SID}” ]]; then
log_date “Cleaning up old files in d i r / {dir}/ dir/{ORACLE_SID}”
rm “ d i r / {dir}/ dir/{ORACLE_SID}/”*
if [[ “$?” -ne 0 ]]; then
error_message
fi
else
mkdir -p “ d i r / {dir}/ dir/{ORACLE_SID}”
if [[ “$?” -ne 0 ]]; then
error_message
fi
fi
done
case语句
通过2个空格缩进可选项。
在同一行可选项的模式右圆括号之后和结束符 ;; 之前各需要一个空格。
长可选项或者多命令可选项应该被拆分成多行,模式、操作和结束符 ;; 在不同的行。
匹配表达式比 case 和 esac 缩进一级。多行操作要再缩进一级。一般情况下,不需要引用匹配表达式。模式表达式前面不应该出现左括号。避免使用 ;& 和 ;;& 符号。
case “${expression}” in
a)
variable="…"
some_command “ v a r i a b l e " " {variable}" " variable""{other_expr}” …
;;
absolute)
actions=“relative”
another_command “ a c t i o n s " " {actions}" " <