@@ -120,7 +120,7 @@ _comp_have_command()
120
120
{
121
121
# Completions for system administrator commands are installed as well in
122
122
# case completion is attempted via `sudo command ...'.
123
- PATH=$PATH :/usr/sbin:/sbin:/usr/local/sbin type $1 & > /dev/null
123
+ PATH=$PATH :/usr/sbin:/sbin:/usr/local/sbin type " $1 " & > /dev/null
124
124
}
125
125
126
126
_comp_deprecate_func _have _comp_have_command
@@ -132,7 +132,7 @@ _comp_deprecate_func _have _comp_have_command
132
132
have ()
133
133
{
134
134
unset -v have
135
- _comp_have_command $1 && have=yes
135
+ _comp_have_command " $1 " && have=yes
136
136
}
137
137
138
138
# This function checks whether a given readline variable
@@ -274,10 +274,11 @@ _upvar()
274
274
echo " bash_completion: $FUNCNAME : deprecated function," \
275
275
" use _upvars instead" >&2
276
276
if unset -v " $1 " ; then # Unset & validate varname
277
+ # shellcheck disable=SC2140 # TODO
277
278
if (( $# == 2 )) ; then
278
- eval $1 =\"\$ 2\" # Return single value
279
+ eval " $1 " =\"\$ 2\" # Return single value
279
280
else
280
- eval $1 =\(\"\$ " {@:2}" \"\) # Return array
281
+ eval " $1 " =\(\"\$ " {@:2}" \"\) # Return array
281
282
fi
282
283
fi
283
284
}
@@ -312,8 +313,8 @@ _upvars()
312
313
return 1
313
314
}
314
315
# Assign array of -aN elements
315
- # shellcheck disable=SC2015 # TODO
316
- [[ $2 ]] && unset -v " $2 " && eval $2 =\(\"\$ " {@:3:${1# -a} }" \"\) &&
316
+ # shellcheck disable=SC2015,SC2140 # TODO
317
+ [[ $2 ]] && unset -v " $2 " && eval " $2 " =\(\"\$ " {@:3:${1# -a} }" \"\) &&
317
318
shift $(( ${1# -a} + 2 )) || {
318
319
echo bash_completion: \
319
320
" $FUNCNAME : \` $1 ${2+ } $2 ': missing argument(s)" \
@@ -324,7 +325,7 @@ _upvars()
324
325
-v)
325
326
# Assign single value
326
327
# shellcheck disable=SC2015 # TODO
327
- [[ $2 ]] && unset -v " $2 " && eval $2 =\"\$ 3\" &&
328
+ [[ $2 ]] && unset -v " $2 " && eval " $2 " =\"\$ 3\" &&
328
329
shift 3 || {
329
330
echo " bash_completion: $FUNCNAME : $1 :" \
330
331
" missing argument(s)" >&2
@@ -559,8 +560,8 @@ __get_cword_at_cursor_by_ref()
559
560
(( index < 0 )) && index=0
560
561
fi
561
562
562
- local " $2 " " $3 " " $4 " && _upvars -a${# words[@]} $2 ${words+" ${words[@]} " } \
563
- -v $3 " $cword " -v $4 " ${cur: 0: index} "
563
+ local " $2 " " $3 " " $4 " && _upvars -a${# words[@]} " $2 " ${words+" ${words[@]} " } \
564
+ -v " $3 " " $cword " -v " $4 " " ${cur: 0: index} "
564
565
}
565
566
566
567
# Get the word to complete and optional previous words.
@@ -771,9 +772,9 @@ _quote_readline_by_ref()
771
772
{
772
773
if [[ $1 == \' * ]]; then
773
774
# Leave out first character
774
- printf -v $2 %s " ${1: 1} "
775
+ printf -v " $2 " %s " ${1: 1} "
775
776
else
776
- printf -v $2 %q " $1 "
777
+ printf -v " $2 " %q " $1 "
777
778
778
779
# If result becomes quoted like this: $'string', re-evaluate in order
779
780
# to drop the additional quoting. See also:
@@ -831,7 +832,7 @@ _filedir()
831
832
832
833
reset=$( shopt -po noglob)
833
834
set -o noglob
834
- toks+=($( compgen " ${opts[@]} " -- $quoted ) )
835
+ toks+=($( compgen " ${opts[@]} " -- " $quoted " ) )
835
836
IFS=' '
836
837
$reset
837
838
IFS=$' \n '
@@ -841,7 +842,7 @@ _filedir()
841
842
$arg && ${# toks[@]} -lt 1 ]] && {
842
843
reset=$( shopt -po noglob)
843
844
set -o noglob
844
- toks+=($( compgen -f ${plusdirs+" ${plusdirs[@]} " } -- $quoted ) )
845
+ toks+=($( compgen -f ${plusdirs+" ${plusdirs[@]} " } -- " $quoted " ) )
845
846
IFS=' '
846
847
$reset
847
848
IFS=$' \n '
@@ -883,8 +884,8 @@ _variables()
883
884
# Completing $var / ${var / ${!var / ${#var
884
885
if [[ $cur == ' ${' * ]]; then
885
886
local arrs vars
886
- vars=($( compgen -A variable -P ${BASH_REMATCH[1]} -S ' }' -- ${BASH_REMATCH[3]} ) )
887
- arrs=($( compgen -A arrayvar -P ${BASH_REMATCH[1]} -S ' [' -- ${BASH_REMATCH[3]} ) )
887
+ vars=($( compgen -A variable -P " ${BASH_REMATCH[1]} " -S ' }' -- " ${BASH_REMATCH[3]} " ) )
888
+ arrs=($( compgen -A arrayvar -P " ${BASH_REMATCH[1]} " -S ' [' -- " ${BASH_REMATCH[3]} " ) )
888
889
if (( ${# vars[@]} == 1 && ${# arrs[@]} != 0 )) ; then
889
890
# Complete ${arr with ${array[ if there is only one match, and that match is an array variable
890
891
compopt -o nospace
@@ -902,7 +903,7 @@ _variables()
902
903
# Complete ${array[i with ${array[idx]}
903
904
local reset= $( shopt -po noglob) IFS= $' \n '
904
905
set -o noglob
905
- COMPREPLY+= ($( compgen -W ' $(printf %s\\n "${!' ${BASH_REMATCH[2]} ' [@]}")' \
906
+ COMPREPLY+= ($( compgen -W ' $(printf %s\\n "${!' " ${BASH_REMATCH[2]} " ' [@]}")' \
906
907
-P " ${BASH_REMATCH[1]}${BASH_REMATCH[2]} [" -S ' ]}' -- " ${BASH_REMATCH[3]} " ) )
907
908
IFS= $' \t\n '
908
909
$reset
@@ -1101,7 +1102,7 @@ _comp_initialize()
1101
1102
;;
1102
1103
esac
1103
1104
cur=${cur## " $redir " }
1104
- _filedir $xspec
1105
+ _filedir " $xspec "
1105
1106
return 1
1106
1107
fi
1107
1108
@@ -1187,7 +1188,10 @@ _parse_help()
1187
1188
(
1188
1189
case $cmd in
1189
1190
-) exec cat ;;
1190
- *) _comp_dequote "$cmd " && LC_ALL=C "$ret " ${2:- --help} 2 >& 1 ;;
1191
+ *)
1192
+ # shellcheck disable=SC2086
1193
+ _comp_dequote "$cmd " && LC_ALL=C "$ret " ${2:- --help} 2 >& 1
1194
+ ;;
1191
1195
esac
1192
1196
) |
1193
1197
while read -r line; do
@@ -1224,7 +1228,10 @@ _parse_usage()
1224
1228
(
1225
1229
case $cmd in
1226
1230
-) exec cat ;;
1227
- *) _comp_dequote "$cmd " && LC_ALL=C "$ret " ${2:- --usage} 2 >& 1 ;;
1231
+ *)
1232
+ # shellcheck disable=SC2086
1233
+ _comp_dequote "$cmd " && LC_ALL=C "$ret " ${2:- --usage} 2 >& 1
1234
+ ;;
1228
1235
esac
1229
1236
) |
1230
1237
while read -r line; do
@@ -1237,7 +1244,7 @@ _parse_usage()
1237
1244
# Treat as bundled short options
1238
1245
for (( i = 1 ; i < ${# option} ; i++ )) ; do
1239
1246
char=${option: i: 1}
1240
- [[ $char != ' [' ]] && printf ' %s\n' -$char && rc=0
1247
+ [[ $char != ' [' ]] && printf ' %s\n' -" $char " && rc=0
1241
1248
done
1242
1249
;;
1243
1250
* )
@@ -1392,7 +1399,7 @@ _ncpus()
1392
1399
local var=NPROCESSORS_ONLN
1393
1400
[[ $OSTYPE == * @ (linux| msys| cygwin)* ]] && var=_$var
1394
1401
local n=$( getconf $var 2> /dev/null)
1395
- printf %s ${n:- 1}
1402
+ printf %s " ${n:- 1} "
1396
1403
}
1397
1404
1398
1405
# Perform tilde (~) completion
@@ -1409,7 +1416,7 @@ _tilde()
1409
1416
# 2>/dev/null for direct invocation, e.g. in the _tilde unit test
1410
1417
(( result > 0 )) && compopt -o filenames 2> /dev/null
1411
1418
fi
1412
- return $result
1419
+ return " $result "
1413
1420
}
1414
1421
1415
1422
# Expand variable starting with tilde (~)
@@ -1437,7 +1444,7 @@ _tilde()
1437
1444
__expand_tilde_by_ref ()
1438
1445
{
1439
1446
if [[ ${! 1-} == \~ * ]]; then
1440
- eval $1 =" $( printf ~ %q " ${! 1# \~ } " ) "
1447
+ eval " $1 " =" $( printf ~ %q " ${! 1# \~ } " ) "
1441
1448
fi
1442
1449
} # __expand_tilde_by_ref()
1443
1450
@@ -1662,7 +1669,7 @@ _modules()
1662
1669
{
1663
1670
local modpath
1664
1671
modpath=/lib/modules/$1
1665
- COMPREPLY=($( compgen -W " $( command ls -RL $modpath 2> /dev/null |
1672
+ COMPREPLY=($( compgen -W " $( command ls -RL " $modpath " 2> /dev/null |
1666
1673
command sed -ne ' s/^\(.*\)\.k\{0,1\}o\(\.[gx]z\)\{0,1\}$/\1/p' \
1667
1674
-e ' s/^\(.*\)\.ko\.zst$/\1/p' ) " -- " $cur " ) )
1668
1675
}
@@ -1938,6 +1945,7 @@ _known_hosts()
1938
1945
local options
1939
1946
[[ ${1-} == -a || ${2-} == -a ]] && options=-a
1940
1947
[[ ${1-} == -c || ${2-} == -c ]] && options+=" -c"
1948
+ # shellcheck disable=SC2086
1941
1949
_known_hosts_real ${options-} -- " $cur "
1942
1950
} # _known_hosts()
1943
1951
@@ -1977,7 +1985,7 @@ _included_ssh_config_files()
1977
1985
if [[ -r $f && ! -d $f ]]; then
1978
1986
config+=(" $f " )
1979
1987
# The Included file is processed to look for Included files in itself
1980
- _included_ssh_config_files $f
1988
+ _included_ssh_config_files " $f "
1981
1989
fi
1982
1990
done
1983
1991
fi
@@ -2240,7 +2248,7 @@ _cd()
2240
2248
for i in ${CDPATH//:/ $' \n ' } ; do
2241
2249
# create an array of matched subdirs
2242
2250
k=${# COMPREPLY[@]}
2243
- for j in $( compgen -d -- $i /$cur ) ; do
2251
+ for j in $( compgen -d -- " $i /$cur " ) ; do
2244
2252
if [[ ($mark_symdirs && -L $j || $mark_dirs && ! -L $j ) && ! -d ${j# " $i /" } ]]; then
2245
2253
j+=" /"
2246
2254
fi
@@ -2365,7 +2373,7 @@ _comp_command_offset()
2365
2373
# FIXME: should we take "+o opt" into account?
2366
2374
cspec=${cspec#* -o }
2367
2375
opt=${cspec%% * }
2368
- compopt -o $opt
2376
+ compopt -o " $opt "
2369
2377
cspec=${cspec# " $opt " }
2370
2378
done
2371
2379
else
@@ -2457,7 +2465,7 @@ _longopt()
2457
2465
COMPREPLY=($( compgen -W " $( LC_ALL=C $1 --help 2>&1 |
2458
2466
while read -r line; do
2459
2467
[[ $line =~ --[A-Za-z0-9]+ ([-_][A-Za-z0-9]+)* = ? ]] &&
2460
- printf ' %s\n' ${BASH_REMATCH[0]}
2468
+ printf ' %s\n' " ${BASH_REMATCH[0]} "
2461
2469
done)" -- " $cur " ))
2462
2470
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
2463
2471
elif [[ $1 == *@(rmdir|chroot) ]]; then
@@ -2490,7 +2498,7 @@ _filedir_xspec()
2490
2498
toks=($(
2491
2499
compgen -d -- " $( quote_readline " $cur " ) " | {
2492
2500
while read -r tmp; do
2493
- printf ' %s\n' $tmp
2501
+ printf ' %s\n' " $tmp "
2494
2502
done
2495
2503
}
2496
2504
) )
@@ -2509,7 +2517,7 @@ _filedir_xspec()
2509
2517
toks+=($(
2510
2518
eval compgen -f -X " '!$xspec '" -- ' $(quote_readline "$cur")' | {
2511
2519
while read -r tmp; do
2512
- [[ $tmp ]] && printf ' %s\n' $tmp
2520
+ [[ $tmp ]] && printf ' %s\n' " $tmp "
2513
2521
done
2514
2522
}
2515
2523
) )
@@ -2750,7 +2758,7 @@ unset -v _comp__init_compat_dir _comp__init_file
2750
2758
# garbages of suppressed command outputs.
2751
2759
_comp__init_user_file=${BASH_COMPLETION_USER_FILE:- ~/ .bash_completion}
2752
2760
[[ $_comp__init_user_file != " ${BASH_SOURCE[0]} " && $_comp__init_user_file != /dev/null && -r $_comp__init_user_file && -f $_comp__init_user_file ]] &&
2753
- . $_comp__init_user_file
2761
+ . " $_comp__init_user_file "
2754
2762
unset -v _comp__init_user_file
2755
2763
2756
2764
unset -f have
0 commit comments