SC2250 – ShellCheck Wiki

See this page on GitHub

Sitemap


Prefer putting braces around variable references even when not strictly required.

Optional - require-variable-braces

This is an optional rule, which means that it has a special "long name" and is not enabled by default. See the optional page for more details. In short, you have to enable it with the long name instead of the "SC" code like you would with a normal rule:

.shellcheckrc

enable=require-variable-braces # SC2250

Problematic code:

partial_path='example'

curl "http://example.com/$partial_path_version/explain.html"

Correct code:

partial_path='example'

curl "http://example.com/${partial_path}_version/explain.html"

Rationale:

If a variable gets called, and there is a string that gets appended to the variable that could get misinterpreted as possibly part of the name of the variable. Then it will not call the right variable.


ShellCheck is a static analysis tool for shell scripts. This page is part of its documentation.