]> git.ipfire.org Git - thirdparty/grub.git/commit
util/bash-completion: Fix SC2207 shellcheck warning
authort.feng <fengtao40@huawei.com>
Tue, 6 Dec 2022 13:49:29 +0000 (21:49 +0800)
committerDaniel Kiper <daniel.kiper@oracle.com>
Wed, 7 Dec 2022 22:38:27 +0000 (23:38 +0100)
commit61e4f408b08d49c24cc2f183078ef687cf8e5bc5
tree7c7955d71d40707f2fb3c1c38857705d52545d30
parent2029c4822b64ab0365340e35387bbcbd311b94b4
util/bash-completion: Fix SC2207 shellcheck warning

SC2207 (warning): Prefer mapfile or read -a to split
command output (or quote to avoid splitting).

In grub-completion.bash.in line 56:
        COMPREPLY=($(compgen -P "${2-}" -W "${1-}" -S "${4-}" -- "$cur"))
                   ^-- SC2207 (warning)

In grub-completion.bash.in line 119:
        COMPREPLY=( $(compgen \
                    ^-- SC2207 (warning)

In grub-completion.bash.in line 128:
    COMPREPLY=( $( compgen -f -X '!*/*.mod' -- "${grub_dir}/$cur" | {
                ^-- SC2207 (warning)

COMPREPLY=($(command)) are doing unquoted command expansion in an array.
This will invoke the shell's sloppy word splitting and glob expansion.

If we want to split the output into lines or words, use read -r and
loops will be better. This prevents the shell from doing unwanted
splitting and glob expansion, and therefore avoiding problems with
output containing spaces or special characters.

More: https://github.com/koalaman/shellcheck/wiki/SC2207

Signed-off-by: t.feng <fengtao40@huawei.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
util/bash-completion.d/grub-completion.bash.in