Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test beginning with "${ and "$(" generate an at times confusing sc1009 and for "$( a potentially incorrect sc1083 message. #3091

Open
2 tasks done
dshuman52 opened this issue Nov 26, 2024 · 0 comments

Comments

@dshuman52
Copy link

dshuman52 commented Nov 26, 2024

For bugs

This is a close relative of issue #3085 however I believe an entirely different issue.

  • SC1009 message
  • documentation (WIKI) makes no reference to inline commands "$( ... )" or "${ ... }" variable references.
  • The message appears to be generic meaning shellcheck has no idea what the code means.
  • SC1083 - message
  • appears to make an assumption that anything starting with "$( is an inline command (not entirely invalid)
  • The WIKI for sc1083 appears to be completely inappropriate in the shown case
  • the string in this case IS enclosed in double quotes meaning one of the suggested solutions already exists in the code
  • one of the examples shows an intended variable reference being assumed to be a command by shellcheck because it starts "$(

For new checks and feature suggestions

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

The error codes presented are directly from shellcheck.net

The following shows the inappropriate use (as described above) of the SC1083 message to improve a prior SC1009 message.

#!/bin/bash
b[1]='2'

a="$(b[c]}"

echo "a=${a}"

The results for the above follow: (the solution is to replace the leading ( with a { not any of the suggested solutions)


$ shellcheck myscript
 
[Line 4:](javascript:setPosition(4, 6))
a="$(b[c]}"
     ^-- [SC1009](https://www.shellcheck.net/wiki/SC1009) (info): The mentioned syntax error was in this simple command.
         ^-- [SC1083](https://www.shellcheck.net/wiki/SC1083) (warning): This } is literal. Check expression (missing ;/\n?) or quote it.
 
[Line 6:](javascript:setPosition(6, 13))
echo "a=${a}"
            ^-- [SC1073](https://www.shellcheck.net/wiki/SC1073) (error): Couldn't parse this double quoted string. Fix to allow more checks.
 
[Line 7:](javascript:setPosition(7, 1))

^-- [SC1072](https://www.shellcheck.net/wiki/SC1072) (error): Expected end of double quoted string. Fix any mentioned problems and try again.

$

flipping the { ... ) changes the results as follows

#!/bin/bash
b[1]='2'

a="${b[c])"

echo "a=${a}"

results follow: The SC1009 message appears be be correct but very vague. The additional errors on the echo statement would appear to be completely bogus. Indicating solving the first error seems to be a priority considering that subsequent errors may not be errors at all.


$ shellcheck myscript
 
[Line 4:](javascript:setPosition(4, 4))
a="${b[c])"
   ^-- [SC1009](https://www.shellcheck.net/wiki/SC1009) (info): The mentioned syntax error was in this parameter expansion.
 
[Line 6:](javascript:setPosition(6, 13))
echo "a=${a}"
            ^-- [SC1073](https://www.shellcheck.net/wiki/SC1073) (error): Couldn't parse this double quoted string. Fix to allow more checks.
             ^-- [SC1072](https://www.shellcheck.net/wiki/SC1072) (error): Expected end of double quoted string. Fix any mentioned problems and try again.

$

Here's what shellcheck currently says:

see above following each example

Here's what I wanted or expected to see:

In both cases identification of the mismatched ( ... } or { ... ) would point directly to the probable error. Leaving it to the user to determine if "$( ... }" is a command that should end in ')"' or a variable reference (this case) that should start with '"${'.

Ideally the enclosing double quotes in "$? ... ?" would prevent the error identification in the echo statement in the second case where a="${b[c])" was coded.

Thanks.

@dshuman52 dshuman52 changed the title test beginning with "${ and "$(" generate inconsistent (and at times confusing) sc1009 and for "$( an inconsistent and potentially incorrect sc1083 messages. test beginning with "${ and "$(" generate inconsistent (and at times confusing) sc1009 and for "$( an inconsistent and potentially incorrect sc1083 message. Nov 26, 2024
@dshuman52 dshuman52 changed the title test beginning with "${ and "$(" generate inconsistent (and at times confusing) sc1009 and for "$( an inconsistent and potentially incorrect sc1083 message. test beginning with "${ and "$(" generate an at times confusing sc1009 and for "$( an inconsistent and potentially incorrect sc1083 message. Nov 26, 2024
@dshuman52 dshuman52 changed the title test beginning with "${ and "$(" generate an at times confusing sc1009 and for "$( an inconsistent and potentially incorrect sc1083 message. test beginning with "${ and "$(" generate an at times confusing sc1009 and for "$( a potentially incorrect sc1083 message. Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant