docs: update

This commit is contained in:
Dylan Araps 2018-05-04 17:05:13 +10:00
parent ffd711a4ea
commit 1a3c8638e1
1 changed files with 12 additions and 10 deletions

View File

@ -41,6 +41,8 @@ request on the repo and our Travis.ci hook will run ShellCheck for you.
## No no's ## No no's
- Dont use `echo`.
- Use `printf "%s\n"`
- Dont use `bc`. - Dont use `bc`.
- Dont use `sed`. - Dont use `sed`.
- Use `bash`'s built-in [parameter expansion](http://wiki.bash-hackers.org/syntax/pe). - Use `bash`'s built-in [parameter expansion](http://wiki.bash-hackers.org/syntax/pe).
@ -52,21 +54,21 @@ request on the repo and our Travis.ci hook will run ShellCheck for you.
## If Statements ## If Statements
If the test only has one command inside of it; use the compact `if` If the test only has one command inside of it; use the compact test
syntax. Otherwise the normal `if`/`fi` is just fine. syntax. Otherwise the normal `if`/`fi` is just fine.
```sh ```sh
# Bad # Bad
if [[ "$var" ]]; then if [[ "$var" ]]; then
echo "$var" printf "%s\n" "$var"
fi fi
# Good # Good
[[ "$var" ]] && echo "$var" [[ "$var" ]] && printf "%s\n" "$var"
# Also good (Use this for longer lines). # Also good (Use this for longer lines).
[[ "$var" ]] && \ [[ "$var" ]] && \
echo "$var" printf "%s\n" "$var"
``` ```
@ -77,16 +79,16 @@ Case statements need to be formatted in a specific way.
```sh ```sh
# Good example (Notice the indentation). # Good example (Notice the indentation).
case "$var" in case "$var" in
1) echo 1 ;; 1) printf "%s\n" 1 ;;
2) 2)
echo 1 printf "%s\n" "1"
echo 2 printf "%s\n" "2"
;; ;;
*) *)
echo 1 printf "%s\n" "1"
echo 2 printf "%s\n" "2"
echo 3 printf "%s\n" "3"
;; ;;
esac esac
``` ```