From f12b2c6d30dffdfce60b366c965550c6e8fe63b6 Mon Sep 17 00:00:00 2001 From: elreydetoda Date: Fri, 17 Apr 2020 14:17:05 -0400 Subject: [PATCH] give an explaination behind this shellcheck code. --- SC2250.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/SC2250.md b/SC2250.md index 8ffecec..fdf0ac2 100644 --- a/SC2250.md +++ b/SC2250.md @@ -1,3 +1,26 @@ # Prefer putting braces around variable references even when not strictly required. This error is optional and not enabled by default. + +## Problematic code: + +```shell +partial_path='example' + +curl "http://example.com/$partial_path_version/explain.html" +``` + +## Correct code: + +```shell +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. + +## Related resources: +- [StackOverflow: How do we separate variables from letters in shell scripting](https://stackoverflow.com/questions/18320133/how-do-we-separate-variables-from-letters-in-shell-scripting) \ No newline at end of file