From 90476bc6333f60923a701257b8db5123c605e240 Mon Sep 17 00:00:00 2001 From: Marc <46978960+marc-hb@users.noreply.github.com> Date: Tue, 17 Mar 2020 11:31:14 -0700 Subject: [PATCH] Revert 0bcac9013f2ec5a11132bbdefa4433988ae1cade...4d7b4d79587e7977f4b5de5145369a1bcebd151c on SC2155 --- SC2155.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/SC2155.md b/SC2155.md index 7fafbce..11a7e74 100644 --- a/SC2155.md +++ b/SC2155.md @@ -65,3 +65,16 @@ readonly foo="$(mycmd)" foo="$(mycmd)" readonly foo ``` + +### Word splitting and quoting issue with dash, maybe others + +A serious quoting problem with dash is another reason to declare and assign separately. Dash is the [default, `/bin/sh` shell on Ubuntu](https://wiki.ubuntu.com/DashAsBinSh). More specifically, dash version 0.5.8-2.10 and others cannot run this code: +```sh +VAR1='white spa/ce' +local var2=$(printf '%s' "${VAR1}") +``` +While this runs fine in other shells, [dash doesn't treat this as an assignment](http://mywiki.wooledge.org/BashPitfalls#local_var.3D.24.28cmd.29) and fails like this: +``` +local: spa/ce: bad variable name +``` +After separating this runs fine in any shell. \ No newline at end of file