From 3f39f310dc07c0950695153a626a2d0a444c9fdd Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Mon, 7 Sep 2020 21:05:27 -0700 Subject: [PATCH] Created SC3024 (markdown) --- SC3024.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 SC3024.md diff --git a/SC3024.md b/SC3024.md new file mode 100644 index 0000000..e28d0ed --- /dev/null +++ b/SC3024.md @@ -0,0 +1,29 @@ +## In POSIX sh, += is undefined. + +(or "In dash, ... is not supported." when using `dash`) + +### Problematic code: + +```sh +var="Hello " +var+="World" +``` + +### Correct code: + +```sh +var="Hello " +var="${var}World" +``` + +### Rationale: + +Using `+=` to concatenate to an existing variable is a ksh/bash extension. For POSIX sh or dash, write out the full expression. Be careful to use braces if the text you append could be confused for a variable (as in the example, to avoid `$varWorld` being interpreted as `${varWorld}`) + +### Exceptions: + +None. + +### Related resources: + +* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!