Ranges can only match single char
~/Documents/Math/shellcheck-v0.10.0/shellcheck rep-factors.sh
In rep-factors.sh line 41:
comp=$(sed -n "${j}p" "${filename}" | jq -r .[\"input-decimal\"]);
^-----------------^ SC2102 (info): Ranges can only match single chars (mentioned due to duplicates).
For more information:
https://www.shellcheck.net/wiki/SC2102 -- Ranges can only match single char...
v0.10.0 stable release used I used sed to extract a line from a file which is a json object, so I used jq to extract json element
I understand what you are reaching towards but this is frankly speaking a pretty lazy and bad issue description.
Ignore the problem with a directive.
Please do not ignore this shellcheck message. It is completely valid and refers to a bug in your shell script.
Please quote your strings properly, single quotes don't hurt.
In your code .["input-decimal"] is interpreted as a shell glob.
Example:
touch .i
echo '{"i": "hello bug"}' | jq -r .[\"input-decimal\"]
# prints hello bug
It is completely valid and refers to a bug in your shell script.
We are still guessing though as the issue description is not clear. To me this report is invalid and should be closed.
We are still guessing though as the issue description is not clear.
The intent is pretty clear I think. @xubuntu4iran wants to extract the field "input-decimal" from the JSON object on line $j.
But because he doesn't quote this JQ code correctly it will be interpreted as a glob by the shell and it will blow up in his face if by chance any file matching .[input-decml"] exists.
It's pure luck his code seems to work.
To me this report is invalid and should be closed.
Agreed. 100% not a bug in shellcheck.
Description added to first post, @sideeffect42 how to edit my script if it is not a bug
Please do not ignore this shellcheck message. It is completely valid and refers to a bug in your shell script.
Please quote your strings properly, single quotes don't hurt. In your code
.["input-decimal"]is interpreted as a shell glob.Example:
touch .i echo '{"i": "hello bug"}' | jq -r .["input-decimal"]
prints hello bug
for me , it printed null echo '{"i": "hello bug"}' | jq -r .["input-decimal"] null
Description added to first post, @sideeffect42 how to edit my script if it is not a bug
@xubuntu4iran: like I had written already, you have to quote your JQ code:
comp=$(sed -n "${j}p" "${filename}" | jq -r '.["input-decimal"]')
Example: touch .i echo '{"i": "hello bug"}' | jq -r .["input-decimal"]
for me , it printed null echo '{"i": "hello bug"}' | jq -r .["input-decimal"] null
You have to run the complete example I posted.
First:
touch .i
And then:
echo '{"i": "hello bug"}' | jq -r .[\"input-decimal\"]
Or run just touch .i and then your code and you will see it misbehave.