Added introduction.

This commit is contained in:
Dylan Araps
2018-06-20 13:03:53 +10:00
parent fe6e2cd195
commit f614dc3cfb
20 changed files with 1344 additions and 1321 deletions

View File

@@ -1,51 +1,13 @@
# Obsolete Syntax
# Performance
## Shebang
## Disable Unicode
Use `#!/usr/bin/env bash` instead of `#!/bin/bash`.
- The former searches the user's `PATH` to find the `bash` binary.
- The latter assumes it is always installed to `/bin/` which can cause issues.
If your script doesn't require unicode, you can disable it for a speed boost. Results may vary but I've seen an improvement in Neofetch and some other smaller programs.
```shell
# Right:
#!/usr/bin/env bash
# Wrong:
#!/bin/bash
```
## Command Substitution
Use `$()` instead of `` ` ` ``.
```shell
# Right.
var="$(command)"
# Wrong.
var=`command`
# $() can easily be nested whereas `` cannot.
var="$(command "$(command)")"
```
## Function Declaration
Don't use the `function` keyword, it reduces compatibility with older versions of `bash`.
```shell
# Right.
do_something() {
# ...
}
# Wrong.
function do_something() {
# ...
}
# Disable unicode.
LC_ALL=C
LANG=C
```
<!-- CHAPTER END -->