mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2006 (markdown)
23
SC2006.md
Normal file
23
SC2006.md
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# Use $(..) instead of deprecated `..`
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
echo "Current time: `date`"
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
echo "Current time: $(date)"
|
||||||
|
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
Backtick command substitution `` `..` `` is legacy syntax with several problems.
|
||||||
|
|
||||||
|
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's exceptionally hard to nest.
|
||||||
|
|
||||||
|
`$(..)` command substitution has none of these problems, and is therefore strongly encouraged.
|
||||||
|
|
||||||
|
### Contraindications
|
||||||
|
|
||||||
|
None.
|
Reference in New Issue
Block a user