From 33b77567e3f46f4a9000bd9d4e3c2697eabd170d Mon Sep 17 00:00:00 2001 From: koalaman Date: Thu, 23 Apr 2015 14:20:55 -0700 Subject: [PATCH] Created SC2041 (markdown) --- SC2041.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 SC2041.md diff --git a/SC2041.md b/SC2041.md new file mode 100644 index 0000000..10bdde8 --- /dev/null +++ b/SC2041.md @@ -0,0 +1,25 @@ +## This is a literal string. To run as a command, use $(seq 1 10) + +### Problematic code: + + for i in 'seq 1 10' + do + echo "$i" + done + +### Correct code: + + for i in $(seq 1 10) + do + echo "$i" + done + +### Rationale: + +The intent was to run the code in the single quotes. This would have worked with slanted backticks, `` `..` ``, but here the very similar looking single quotes `'..'` were used, resulting in a string literal instead of command output. + +This is one of the many problems with backticks, so it's better to use `$(..)` to expand commands. + +### Exceptions: + +None. \ No newline at end of file