docs: update
This commit is contained in:
parent
ffd711a4ea
commit
1a3c8638e1
|
@ -41,6 +41,8 @@ request on the repo and our Travis.ci hook will run ShellCheck for you.
|
||||||
|
|
||||||
## No no's
|
## No no's
|
||||||
|
|
||||||
|
- Don’t use `echo`.
|
||||||
|
- Use `printf "%s\n"`
|
||||||
- Don’t use `bc`.
|
- Don’t use `bc`.
|
||||||
- Don’t use `sed`.
|
- Don’t 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
|
||||||
```
|
```
|
||||||
|
|
Reference in New Issue