From b86b50153e938f8e917f91e336ec0242fabaf518 Mon Sep 17 00:00:00 2001 From: koalaman Date: Wed, 7 May 2014 20:34:35 -0700 Subject: [PATCH] Created SC2139 (markdown) --- SC2139.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 SC2139.md diff --git a/SC2139.md b/SC2139.md new file mode 100644 index 0000000..3ca5827 --- /dev/null +++ b/SC2139.md @@ -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. \ No newline at end of file