From 0ab68c1a33d83033f046bf00847a42aecfafbf1a Mon Sep 17 00:00:00 2001 From: koalaman Date: Tue, 11 Oct 2016 10:29:26 -0700 Subject: [PATCH] Created SC2037 (markdown) --- SC2037.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 SC2037.md diff --git a/SC2037.md b/SC2037.md new file mode 100644 index 0000000..bd03726 --- /dev/null +++ b/SC2037.md @@ -0,0 +1,20 @@ +## To assign the output of a command, use var=$(cmd) . + +### Problematic code: + +```sh +var=grep -c pattern file +``` + +### Correct code: + +```sh +var=$(grep -c pattern file) +``` +### Rationale: + +To assign the output of a command to a variable, use `$(command substitution)`. Just typing a command after the `=` sign does not work. + +### Exceptions: + +None. \ No newline at end of file