shellcheck
shellcheck copied to clipboard
SC2086 unnecessary for `readonly` assignments
For bugs
- Rule Id: SC2086
- My shellcheck version (
shellcheck --versionor "online"): 0.8.0, online - [x] The rule's wiki page does not already cover this (e.g. https://shellcheck.net/wiki/SC2086)
- [x] I tried on https://www.shellcheck.net/ and verified that this is still a problem on the latest commit
Here's a snippet that shows the problem:
#!/bin/sh
a='b c=d'
readonly e=$a
echo "$e" # "b c=d"
echo "$c" # ""
Here's what shellcheck currently says:
In test line 4:
readonly e=$a
^-- SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
readonly e="$a"
Here's what I wanted or expected to see:
Nothing
See #2443. shellcheck warns here because Ubuntu 20.04 ships with dash 0.5.10.2, where the quotes are necessary (I tested it). Since then the POSIX spec has been updated so that quotes are no longer necessary.