Gentoo Archives: gentoo-portage-dev

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

Replies

Subject Author
Re: [gentoo-portage-dev] Fix all misc. bash errors. Zac Medico <zmedico@g.o>