forked from dylanaraps/pure-bash-bible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchapter15.txt
55 lines (35 loc) · 871 Bytes
/
chapter15.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# OBSOLETE SYNTAX
## Shebang
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.
**NOTE**: There are times when one may have a good reason for using `#!/bin/bash` or another direct path to the binary.
```shell
# Right:
#!/usr/bin/env bash
# Less right:
#!/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
Do not use the `function` keyword, it reduces compatibility with older versions of `bash`.
```shell
# Right.
do_something() {
# ...
}
# Wrong.
function do_something() {
# ...
}
```
<!-- CHAPTER END -->