Skip to content

Assigning and retrieving integers via indirection inside arithmetic expansion #3515

Description

@friendly-bits

For bugs with existing features

  • Rule Id (if any, e.g. SC1000): SC1102, SC2271
  • My shellcheck version (shellcheck --version or "online"): 0.11.0
  • [V] The rule's wiki page does not already cover this (e.g. https://shellcheck.net/wiki/SC2086)
  • [V] I tried on https://www.shellcheck.net/ and verified that this is still a problem on the latest commit

Here's a snippet or screenshot that shows the problem:

#!/bin/sh
a=1
: "$(( v_${a}=5 ))"

Here's what shellcheck currently says:

[Line 3:](javascript:setPosition(3, 4))
: "$(( v_${a}=5 ))"
   ^-- [SC1102](https://www.shellcheck.net/wiki/SC1102) (error): Shells disambiguate $(( differently or not at all. For $(command substitution), add space after $( . For $((arithmetics)), fix parsing errors.
       ^-- [SC2271](https://www.shellcheck.net/wiki/SC2271) (error): For indirection, use arrays, declare "var$n=value", or (for sh) read/eval.

Here's what I wanted or expected to see:

Assigning integers via indirection (and also getting values via indirection) inside arithmetic expansion seems to be universally supported by POSIX-compliant shells: I tested with bash, dash, Busybox ash, ksh93u+m, yash and this works on all of them. I'm not entirely sure whether this is technically 100% POSIX-compliant but I think it might be.

So I expected to see no errors or warnings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions