shellcheck icon indicating copy to clipboard operation
shellcheck copied to clipboard

SC2086 unnecessary for `readonly` assignments

Open climbTheStairs opened this issue 2 years ago • 1 comments

For bugs

  • Rule Id: SC2086
  • My shellcheck version (shellcheck --version or "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

climbTheStairs avatar Aug 22 '23 12:08 climbTheStairs

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.

Ordoviz avatar Aug 23 '23 13:08 Ordoviz