grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH V2 2/4] bash-completion:fix shellcheck SC2207-Warning


From: Daniel Kiper
Subject: Re: [PATCH V2 2/4] bash-completion:fix shellcheck SC2207-Warning
Date: Thu, 1 Dec 2022 20:12:18 +0100

On Wed, Nov 30, 2022 at 04:30:58PM +0800, t.feng wrote:
> 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)
>
> ref:https://github.com/koalaman/shellcheck/wiki/SC2207
>
> Signed-off-by: "t.feng" <fengtao40@huawei.com>
> ---
>  .../bash-completion.d/grub-completion.bash.in | 34 ++++++++++++-------
>  1 file changed, 21 insertions(+), 13 deletions(-)
>
> diff --git a/util/bash-completion.d/grub-completion.bash.in 
> b/util/bash-completion.d/grub-completion.bash.in
> index 93d143480..4749cbc64 100644
> --- a/util/bash-completion.d/grub-completion.bash.in
> +++ b/util/bash-completion.d/grub-completion.bash.in
> @@ -53,7 +53,10 @@ __grubcomp () {
>          ;;
>      *)
>          local IFS=' '$'\t'$'\n'
> -        COMPREPLY=($(compgen -P "${2-}" -W "${1-}" -S "${4-}" -- "$cur"))
> +        COMPREPLY=()
> +        while read -r line; do

I think the "line" variable should be local. Same for other variables below...

And I think it would be nice if you add a patch which marks all existing
functions variables as local.

> +            COMPREPLY+=("${line}")
> +        done < <(compgen -P "${2-}" -W "${1-}" -S "${4-}" -- "$cur")
>          ;;
>      esac
>  }
> @@ -116,24 +119,29 @@ __grub_list_menuentries () {
>
>      if [ -f "$config_file" ];then
>          local IFS=$'\n'
> -        COMPREPLY=( $(compgen \
> -            -W "$( awk -F "[\"']" '/menuentry/ { print $2 }' $config_file )" 
> \
> -            -- "$cur" )) #'# Help emacs syntax highlighting
> +        COMPREPLY=()
> +        while read -r line; do
> +            COMPREPLY+=("${line}")
> +        done < <(compgen \
> +                -W "$( awk -F "[\"']" '/menuentry/ { print $2 }' 
> $config_file )" \
> +                -- "$cur" ) #'# Help emacs syntax highlighting
>      fi
>  }
>
>  __grub_list_modules () {
>      local grub_dir=$(__grub_dir)
>      local IFS=$'\n'
> -    COMPREPLY=( $( compgen -f -X '!*/*.mod' -- "${grub_dir}/$cur" | {
> -         while read -r tmp; do
> -             [ -n "$tmp" ] && {
> -                 tmp=${tmp##*/}
> -                 printf '%s\n' ${tmp%.mod}
> -             }
> -         done
> -         }
> -        ))
> +    COMPREPLY=()
> +    while read -r line; do
> +        COMPREPLY+=("${line}")
> +    done < <(compgen -f -X '!*/*.mod' -- "${grub_dir}/$cur" | {
> +        while read -r tmp; do
> +            [ -n "$tmp" ] && {
> +                tmp=${tmp##*/}
> +                printf '%s\n' ${tmp%.mod}
> +            }
> +        done
> +    })
>  }

Daniel



reply via email to

[Prev in Thread] Current Thread [Next in Thread]