1 |
On Sun, Feb 4, 2018 at 10:45 PM, Zac Medico <zmedico@g.o> wrote: |
2 |
> On 02/04/2018 07:22 PM, R0b0t1 wrote: |
3 |
>> This is everything that shellcheck reported as an error. They are not |
4 |
>> as serious as the globbing issue, but it would be a good idea to |
5 |
>> change them. They are generally "type" issues (e.g. ">" instead of |
6 |
>> "-gt"). |
7 |
>> |
8 |
>> Some changes are shellcheck annotations. Very interesting was: |
9 |
>> |
10 |
>> eval "$x=(\"\${$x[@]}\" ${QA_PREBUILT//\*/.*})" |
11 |
>> |
12 |
>> Which looks like a bad array expansion ("$x[@]"). |
13 |
> |
14 |
> I don't see a shellcheck error for that, using shellcheck-0.4.7. Maybe a |
15 |
> false positive with an older version? |
16 |
> |
17 |
|
18 |
0.4.6, I will see if I can check. |
19 |
|
20 |
>> diff --git a/bin/isolated-functions.sh b/bin/isolated-functions.sh |
21 |
>> index b28e44f18..377b32d90 100644 |
22 |
>> --- a/bin/isolated-functions.sh |
23 |
>> +++ b/bin/isolated-functions.sh |
24 |
>> @@ -82,7 +82,7 @@ __dump_trace() { |
25 |
>> lineno=${BASH_LINENO[${n} - 1]} |
26 |
>> # Display function arguments |
27 |
>> args= |
28 |
>> - if [[ -n "${BASH_ARGV[@]}" ]]; then |
29 |
>> + if [[ -n "${BASH_ARGV[*]}" ]]; then |
30 |
> |
31 |
> I feel like the shellcheck authors might be willing to accept [[ -n |
32 |
> ${BASH_ARGV[@]} ]] or [[ ${BASH_ARGV[@]} ]] as correct, since the |
33 |
> "Problematic code" that they cite involves an incorrect comparison: |
34 |
> |
35 |
> https://github.com/koalaman/shellcheck/wiki/SC2199#problematic-code |
36 |
> |
37 |
|
38 |
This example might be more illustrative: |
39 |
|
40 |
argc () { |
41 |
echo $# |
42 |
} |
43 |
|
44 |
argc "${BASH_ARGV[*]}" |
45 |
argc "${BASH_ARGV[@]}" |
46 |
|
47 |
|
48 |
Output (./test.sh a b): |
49 |
|
50 |
1 |
51 |
2 |
52 |
|
53 |
|
54 |
Which changes the semantics of the tests in which it is present. It is |
55 |
hard to know what [[ is doing; if the same is attempted with [ it |
56 |
would be an error for the same reason that globbing produces errors. |
57 |
See: |
58 |
|
59 |
[ "${BASH_ARGV[*]}" ] |
60 |
[ "${BASH_ARGV[@]}" ] # Fails; [: b: unary operator expected |
61 |
[[ "${BASH_ARGV[*]}" ]] |
62 |
[[ "${BASH_ARGV[@]}" ]] |
63 |
|
64 |
|
65 |
It is possible [[ ignores the extra elements. I can't think of a |
66 |
reason where this would make the results of the test different. At the |
67 |
same time, it might give people the wrong impression of the operation |
68 |
of [. |
69 |
|
70 |
In the sense that [ and [[ represent test(1), anything but the "[*]" |
71 |
expansion is incorrect, as the error message indicates. That [[ treats |
72 |
its arguments specially because it is a feature of the syntax just |
73 |
makes the situation more confusing. |
74 |
|
75 |
Cheers, |
76 |
R0b0t1 |