mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2139 (markdown)
10
SC2139.md
10
SC2139.md
@@ -18,6 +18,14 @@ With double quotes, this particular alias will be defined as `echo /home/me`, so
|
||||
|
||||
By using single quotes or escaping any expansions, we define the alias as `echo $PWD`, which will be expanded when we use the alias. This is the far more common use case.
|
||||
|
||||
Note that even if you expect that the variable will never change, it may still be better to quote it. This prevents a second round of evaluation later:
|
||||
|
||||
default="Can't handle failure, aborting"
|
||||
trap "echo $default; exit 1" err
|
||||
false
|
||||
|
||||
The trap now has a syntax error, because instead of running `echo $default`, it runs `echo Can't handle ..` which has an unmatched single quote. Avoid early expansion unless you're equally comfortable putting `eval` in there.
|
||||
|
||||
### Exceptions
|
||||
|
||||
If you don't mind that your alias definition is expanded at define time, you can ignore this warning.
|
||||
If you don't mind that your alias definition is expanded at define time (and its result expanded again at evaluation time), you can ignore this warning.
|
||||
|
Reference in New Issue
Block a user