mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Make MarkDown easier to parse
11
SC2006.md
11
SC2006.md
@@ -1,20 +1,31 @@
|
|||||||
# Use `$(...)` notation instead of legacy backticked `` `...` ``.
|
# Use `$(...)` notation instead of legacy backticked `` `...` ``.
|
||||||
|
|
||||||
### Problematic code
|
### Problematic code
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
echo "You are running on `uname`"
|
echo "You are running on `uname`"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Correct code
|
### Correct code
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
echo "You are running on $(uname)"
|
echo "You are running on $(uname)"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Rationale
|
### Rationale
|
||||||
|
|
||||||
Backtick command substitution `` `...` `` is legacy syntax with several issues.
|
Backtick command substitution `` `...` `` is legacy syntax with several issues.
|
||||||
|
|
||||||
1. It has a series of undefined behaviors related to quoting in POSIX.
|
1. It has a series of undefined behaviors related to quoting in POSIX.
|
||||||
1. It imposes a custom escaping mode with surprising results.
|
1. It imposes a custom escaping mode with surprising results.
|
||||||
1. It's exceptionally hard to nest.
|
1. It's exceptionally hard to nest.
|
||||||
|
|
||||||
`$(...)` command substitution has none of these problems, and is therefore strongly encouraged.
|
`$(...)` command substitution has none of these problems, and is therefore strongly encouraged.
|
||||||
|
|
||||||
### Exceptions
|
### Exceptions
|
||||||
|
|
||||||
None.
|
None.
|
||||||
|
|
||||||
### Related resources:
|
### Related resources:
|
||||||
|
|
||||||
* [BashFaq: Why is `$(...)` preferred over `` `...` `` (backticks)?](http://mywiki.wooledge.org/BashFAQ/082)
|
* [BashFaq: Why is `$(...)` preferred over `` `...` `` (backticks)?](http://mywiki.wooledge.org/BashFAQ/082)
|
||||||
|
Reference in New Issue
Block a user