Open grische opened 2 months ago
Here is a more advanced example that shows some issues when using globmatching where the glob can be expanded accidentally:
#!/bin/busybox sh
testglob() {
local var1="barfoobar"
local var2="foobar"
local var3="barfoo"
local var4="bar"
[[ ${var1} == *foo* ]] && echo "(unquoted pattern) var1 true" || echo "(unquoted pattern) var1 false"
[[ ${var2} == *foo* ]] && echo "(unquoted pattern) var2 true" || echo "(unquoted pattern) var2 false"
[[ ${var3} == *foo* ]] && echo "(unquoted pattern) var3 true" || echo "(unquoted pattern) var3 false"
[[ ${var4} == *foo* ]] && echo "(unquoted pattern) var4 true" || echo "(unquoted pattern) var4 false"
[[ ${var1} == "*foo*" ]] && echo "(quoted pattern) var1 true" || echo "(quoted pattern) var1 false"
[[ ${var2} == "*foo*" ]] && echo "(quoted pattern) var2 true" || echo "(quoted pattern) var2 false"
[[ ${var3} == "*foo*" ]] && echo "(quoted pattern) var3 true" || echo "(quoted pattern) var3 false"
[[ ${var4} == "*foo*" ]] && echo "(quoted pattern) var4 true" || echo "(quoted pattern) var4 false"
}
rm -f barfoobar xfoox && echo "Neither file barfoobar nor xfoox exist"
testglob
echo
touch barfoobar && echo "File barfoobar exists"
testglob
echo
touch xfoox && echo "File barfoobar and file xfoox exists"
testglob
echo
That will output:
Neither file barfoobar nor xfoox exist
(unquoted pattern) var1 true
(unquoted pattern) var2 true
(unquoted pattern) var3 true
(unquoted pattern) var4 false
(quoted pattern) var1 true
(quoted pattern) var2 true
(quoted pattern) var3 true
(quoted pattern) var4 false
File barfoobar exists
(unquoted pattern) var1 true
(unquoted pattern) var2 false
(unquoted pattern) var3 false
(unquoted pattern) var4 false
(quoted pattern) var1 true
(quoted pattern) var2 true
(quoted pattern) var3 true
(quoted pattern) var4 false
File barfoobar and file xfoox exists
sh: xfoox: unknown operand
(unquoted pattern) var1 false
sh: xfoox: unknown operand
(unquoted pattern) var2 false
sh: xfoox: unknown operand
(unquoted pattern) var3 false
sh: xfoox: unknown operand
(unquoted pattern) var4 false
(quoted pattern) var1 true
(quoted pattern) var2 true
(quoted pattern) var3 true
(quoted pattern) var4 false
$ shellcheck myscript
[Line 10:](javascript:setPosition(10, 19))
[[ ${var1} == *foo* ]] && echo "(unquoted pattern) var1 true" || echo "(unquoted pattern) var1 false"
^-- [SC2330](https://www.shellcheck.net/wiki/SC2330) (error): BusyBox [[ .. ]] does not support glob matching. Use a case statement.
[Line 11:](javascript:setPosition(11, 19))
[[ ${var2} == *foo* ]] && echo "(unquoted pattern) var2 true" || echo "(unquoted pattern) var2 false"
^-- [SC2330](https://www.shellcheck.net/wiki/SC2330) (error): BusyBox [[ .. ]] does not support glob matching. Use a case statement.
[Line 12:](javascript:setPosition(12, 19))
[[ ${var3} == *foo* ]] && echo "(unquoted pattern) var3 true" || echo "(unquoted pattern) var3 false"
^-- [SC2330](https://www.shellcheck.net/wiki/SC2330) (error): BusyBox [[ .. ]] does not support glob matching. Use a case statement.
[Line 13:](javascript:setPosition(13, 19))
[[ ${var4} == *foo* ]] && echo "(unquoted pattern) var4 true" || echo "(unquoted pattern) var4 false"
^-- [SC2330](https://www.shellcheck.net/wiki/SC2330) (error): BusyBox [[ .. ]] does not support glob matching. Use a case statement.
In the above example, the error seems valid, as it requires quoting to work properly. But it should very likely be reworded.
For bugs
shellcheck --version
or "online"): online / ac8fb00504ed6da83fe5c5f83e72e4663ff6b439Here's a snippet or screenshot that shows the problem:
Basic glob matching does seem to work with
BusyBox v1.35.0
:returns
Here's what shellcheck currently says:
Here's what I wanted or expected to see:
No error, but maybe some warning instead (see example below).