| 1 |
This is the rc-scripts style manual. It governs the coding style |
| 2 |
of rc-scripts. Everything here might as well have been spoken by |
| 3 |
God. If you find any issues, please talk to base-system@gentoo.org |
| 4 |
or #gentoo-base on irc.freenode.net. |
| 5 |
|
| 6 |
############# |
| 7 |
# VARIABLES # |
| 8 |
############# |
| 9 |
- User Variables - |
| 10 |
Variables must always be enclosed by {} |
| 11 |
e.g. ${foo} ${bar} |
| 12 |
- Internal Shell Variables - |
| 13 |
Do not use {} with internal variables unless appropriate |
| 14 |
e.g. case $1 in |
| 15 |
e.g. foo=$IFS |
| 16 |
e.g. echo "blah${1}123" |
| 17 |
- Assigning with Quotes - |
| 18 |
When assigning to a variable from another variable, you should |
| 19 |
not need quotes. However, you do when assigning from a subshell. |
| 20 |
e.g. foo=${bar} |
| 21 |
e.g. foo="$(uname -a)" |
| 22 |
|
| 23 |
######### |
| 24 |
# TESTS # |
| 25 |
######### |
| 26 |
- Brackets - |
| 27 |
Always use the [ ... ] form instead of [[ ... ]] as the later only really |
| 28 |
works in bash, and we should support as many shells as we can. |
| 29 |
- Quoting - |
| 30 |
When dealing with strings, you should quote both sides. |
| 31 |
|
| 32 |
############### |
| 33 |
# CODE BLOCKS # |
| 34 |
############### |
| 35 |
- Structure - |
| 36 |
Use the more compact form |
| 37 |
e.g. if ... ; then |
| 38 |
e.g. while ... ; do |
| 39 |
Do not use the older form |
| 40 |
e.g. if ... |
| 41 |
then |
| 42 |
- Functions - |
| 43 |
Use the more compact form |
| 44 |
e.g. foo() { |
| 45 |
Do not lead with 'function ' |
| 46 |
e.g. function foo() { |
| 47 |
|
| 48 |
############ |
| 49 |
# COMMENTS # |
| 50 |
############ |
| 51 |
- General - |
| 52 |
Try to include a comment block before sections |
| 53 |
of code to explain what you're attempting |