mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2139 (markdown)
19
SC2139.md
Normal file
19
SC2139.md
Normal file
@@ -0,0 +1,19 @@
|
||||
## This expands when defined, not when used. Consider escaping.
|
||||
|
||||
### Problematic code:
|
||||
|
||||
alias whereami="echo $PWD"
|
||||
|
||||
### Correct code:
|
||||
|
||||
alias whereami='echo $PWD'
|
||||
|
||||
### Rationale:
|
||||
|
||||
With double quotes, this particular alias will be defined as `echo /home/me`, so it will always print the same path. This is rarely intended.
|
||||
|
||||
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.
|
||||
|
||||
### Contraindications
|
||||
|
||||
If you don't mind that your alias definition is expanded at compile time, you can ignore this warning.
|
Reference in New Issue
Block a user