Add new paragraph "Word splitting and quoting issue with dash, maybe others"

Marc
2019-12-11 17:10:57 -08:00
parent 36c6cf82ba
commit 0bcac9013f

@@ -65,3 +65,16 @@ readonly foo="$(mycmd)"
foo="$(mycmd)" foo="$(mycmd)"
readonly foo 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.