From 2ff0e3e75196a500d27532f98717eeaacac4f1f9 Mon Sep 17 00:00:00 2001 From: koalaman Date: Wed, 2 Sep 2015 21:08:26 -0700 Subject: [PATCH] Created SC1098 (markdown) --- SC1098.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 SC1098.md diff --git a/SC1098.md b/SC1098.md new file mode 100644 index 0000000..0f0220f --- /dev/null +++ b/SC1098.md @@ -0,0 +1,24 @@ +## Quote/escape special characters when using eval, e.g. eval "a=(b)". + +### Problematic code: + + eval $var=(a b) + +### Correct code: + + eval "$var=(a b)" + +### Rationale: + +Shells differ widely in how they handle unescaped parentheses in `eval` expressions. + +* `eval foo=bar` is allowed by dash, bash and ksh. +* `eval foo=(bar)` is allowed by bash and ksh, but not dash. +* `eval $var=(bar)` is allowed by ksh, but not bash or dash. +* `eval foo() ( echo bar; )` is not allowed by any shell. + +Since the expression is evaluated as shell script code anyways, it should be passed in as a literal string without relying on special case parsing rules in the target shell. Quote or escape the characters appropriately. + +### Exceptions: + +None. \ No newline at end of file