@@ -346,7 +346,7 @@ _comp_split()
346346{
347347 local _assign=' =' IFS=$' \t\n '
348348
349- local OPTIND=1 OPTARG=' ' OPTERR=0 _opt
349+ local OPTIND=1 OPTARG=" " OPTERR=0 _opt
350350 while getopts ' :alF:' _opt " $@ " ; do
351351 case $_opt in
352352 a) _assign=' +=' ;;
@@ -396,7 +396,7 @@ _comp_looks_like_path()
396396#
397397__reassemble_comp_words_by_ref ()
398398{
399- local exclude i j line ref
399+ local exclude= " " i j line ref
400400 # Exclude word separator characters?
401401 if [[ $1 ]]; then
402402 # Yes, exclude word separator characters;
@@ -407,7 +407,7 @@ __reassemble_comp_words_by_ref()
407407 # Default to cword unchanged
408408 printf -v " $3 " %s " $COMP_CWORD "
409409 # Are characters excluded which were former included?
410- if [[ -v exclude ]]; then
410+ if [[ $ exclude ]]; then
411411 # Yes, list of word completion separators has shrunk;
412412 line=$COMP_LINE
413413 # Re-assemble words to complete
@@ -531,13 +531,18 @@ __get_cword_at_cursor_by_ref()
531531#
532532_get_comp_words_by_ref ()
533533{
534- local exclude flag i OPTIND=1
534+ local exclude= " " flag i OPTIND=1
535535 local cur cword words=()
536- local upargs=() upvars=() vcur vcword vprev vwords
537- unset -v vcur vcword vprev vwords # workaround for localvar_inherit
536+ local upargs=() upvars=() vcur=" " vcword=" " vprev=" " vwords=" "
538537
539538 while getopts " c:i:n:p:w:" flag " $@ " ; do
540539 case $flag in
540+ [cipw])
541+ if [[ $OPTARG != [a-zA-Z_]* ([a-zA-Z_0-9])? (\[ * \] ) ]]; then
542+ echo " bash_completion: $FUNCNAME : -$flag : invalid variable name \` $OPTARG '" >&2
543+ return 1
544+ fi
545+ ;;&
541546 c) vcur=$OPTARG ;;
542547 i) vcword=$OPTARG ;;
543548 n) exclude=$OPTARG ;;
@@ -566,19 +571,19 @@ _get_comp_words_by_ref()
566571
567572 __get_cword_at_cursor_by_ref " ${exclude-} " words cword cur
568573
569- [[ -v vcur ]] && {
574+ [[ $ vcur ]] && {
570575 upvars+=(" $vcur " )
571576 upargs+=(-v $vcur " $cur " )
572577 }
573- [[ -v vcword ]] && {
578+ [[ $ vcword ]] && {
574579 upvars+=(" $vcword " )
575580 upargs+=(-v $vcword " $cword " )
576581 }
577- [[ -v vprev && $cword -ge 1 ]] && {
582+ [[ $ vprev && $cword -ge 1 ]] && {
578583 upvars+=(" $vprev " )
579584 upargs+=(-v $vprev " ${words[cword - 1]} " )
580585 }
581- [[ -v vwords ]] && {
586+ [[ $ vwords ]] && {
582587 upvars+=(" $vwords " )
583588 upargs+=(-a${# words[@]} $vwords ${words+" ${words[@]} " } )
584589 }
@@ -935,7 +940,7 @@ _comp_initialize()
935940{
936941 local exclude=" " outx errx inx
937942
938- local flag OPTIND=1 OPTARG=' ' OPTERR=0
943+ local flag OPTIND=1 OPTARG=" " OPTERR=0
939944 while getopts " n:e:o:i:s" flag " $@ " ; do
940945 case $flag in
941946 n) exclude+=$OPTARG ;;
@@ -1815,7 +1820,7 @@ _known_hosts()
18151820
18161821 # NOTE: Using `_known_hosts' as a helper function and passing options
18171822 # to `_known_hosts' is deprecated: Use `_known_hosts_real' instead.
1818- local options
1823+ local options= " "
18191824 [[ ${1-} == -a || ${2-} == -a ]] && options=-a
18201825 [[ ${1-} == -c || ${2-} == -c ]] && options+=" -c"
18211826 # shellcheck disable=SC2086
@@ -1882,8 +1887,8 @@ _included_ssh_config_files()
18821887# @return Completions, starting with CWORD, are added to COMPREPLY[]
18831888_known_hosts_real ()
18841889{
1885- local configfile flag prefix=" "
1886- local cur suffix=" " aliases i host ipv4 ipv6
1890+ local configfile= " " flag prefix=" "
1891+ local cur suffix=" " aliases= " " i host ipv4= " " ipv6= " "
18871892 local -a kh tmpkh=() khd=() config=()
18881893
18891894 # TODO remove trailing %foo from entries
@@ -1893,7 +1898,13 @@ _known_hosts_real()
18931898 case $flag in
18941899 a) aliases=' yes' ;;
18951900 c) suffix=' :' ;;
1896- F) configfile=$OPTARG ;;
1901+ F)
1902+ if [[ ! $OPTARG ]]; then
1903+ echo " bash_completion: $FUNCNAME : -F: an empty filename is specified" >&2
1904+ return 1
1905+ fi
1906+ configfile=$OPTARG
1907+ ;;
18971908 p) prefix=$OPTARG ;;
18981909 4) ipv4=1 ;;
18991910 6) ipv6=1 ;;
@@ -1922,7 +1933,7 @@ _known_hosts_real()
19221933 kh=()
19231934
19241935 # ssh config files
1925- if [[ -v configfile ]]; then
1936+ if [[ $ configfile ]]; then
19261937 [[ -r $configfile && ! -d $configfile ]] && config+=(" $configfile " )
19271938 else
19281939 for i in /etc/ssh/ssh_config ~ /.ssh/config ~ /.ssh2/config; do
@@ -1968,7 +1979,7 @@ _known_hosts_real()
19681979 done
19691980 fi
19701981
1971- if [[ ! -v configfile ]]; then
1982+ if [[ ! $ configfile ]]; then
19721983 # Global and user known_hosts files
19731984 for i in /etc/ssh/ssh_known_hosts /etc/ssh/ssh_known_hosts2 \
19741985 /etc/known_hosts /etc/known_hosts2 ~ /.ssh/known_hosts \
@@ -2033,7 +2044,7 @@ _known_hosts_real()
20332044 fi
20342045
20352046 # append any available aliases from ssh config files
2036- if [[ ${# config[@]} -gt 0 && -v aliases ]]; then
2047+ if [[ ${# config[@]} -gt 0 && $ aliases ]]; then
20372048 local -a hosts=($( command sed -ne ' s/^[[:blank:]]*[Hh][Oo][Ss][Tt][[:blank:]=]\{1,\}\(.*\)$/\1/p' " ${config[@]} " ) )
20382049 if (( ${# hosts[@]} != 0 )) ; then
20392050 COMPREPLY+=($( compgen -P " $prefix " \
@@ -2069,13 +2080,13 @@ _known_hosts_real()
20692080 $reset
20702081
20712082 if (( ${# COMPREPLY[@]} )) ; then
2072- if [[ -v ipv4 ]]; then
2083+ if [[ $ ipv4 ]]; then
20732084 COMPREPLY=(" ${COMPREPLY[@]/*:* $suffix / } " )
20742085 fi
2075- if [[ -v ipv6 ]]; then
2086+ if [[ $ ipv6 ]]; then
20762087 COMPREPLY=(" ${COMPREPLY[@]/ +([0-9]).+([0-9]).+([0-9]).+([0-9])$suffix / } " )
20772088 fi
2078- if [[ -v ipv4 || -v ipv6 ]]; then
2089+ if [[ $ ipv4 || $ ipv6 ]]; then
20792090 for i in " ${! COMPREPLY[@]} " ; do
20802091 [[ ${COMPREPLY[i]} ]] || unset -v ' COMPREPLY[i]'
20812092 done
@@ -2113,7 +2124,7 @@ _cd()
21132124 return
21142125 fi
21152126
2116- local mark_dirs=' ' mark_symdirs=' '
2127+ local mark_dirs=" " mark_symdirs=" "
21172128 _comp_readline_variable_on mark-directories && mark_dirs=y
21182129 _comp_readline_variable_on mark-symlinked-directories && mark_symdirs=y
21192130
0 commit comments