@@ -325,6 +325,8 @@ _comp_upvars()
325325# parameter expansions, command substitutions, and other expansions will be
326326# processed. The user-provided strings should not be directly specified to
327327# this argument.
328+ # @return 0 if at least one path is generated, 1 if no path is generated, or 2
329+ # if the usage is incorrect.
328330# @since 2.12
329331_comp_expand_glob ()
330332{
@@ -361,7 +363,7 @@ _comp_expand_glob()
361363 [[ :$_original_opts : == * :nullglob:* ]] || shopt -u nullglob
362364 [[ :$_original_opts : == * :failglob:* ]] && shopt -s failglob
363365 [[ :$_original_opts : == * :noglob:* ]] && set -o noglob
364- return 0
366+ eval " (( \$ {# $1 [@]})) "
365367}
366368
367369# Split a string and assign to an array. This function basically performs
@@ -1652,14 +1654,12 @@ _comp_compgen_configured_interfaces()
16521654 local -a files
16531655 if [[ -f /etc/debian_version ]]; then
16541656 # Debian system
1655- _comp_expand_glob files ' /etc/network/interfaces /etc/network/interfaces.d/*'
1656- (( ${# files[@]} )) || return 0
1657+ _comp_expand_glob files ' /etc/network/interfaces /etc/network/interfaces.d/*' || return 0
16571658 _comp_compgen -U files split -- " $( command sed -ne \
16581659 ' s|^iface \([^ ]\{1,\}\).*$|\1|p' " ${files[@]} " 2> /dev/null) "
16591660 elif [[ -f /etc/SuSE-release ]]; then
16601661 # SuSE system
1661- _comp_expand_glob files ' /etc/sysconfig/network/ifcfg-*'
1662- (( ${# files[@]} )) || return 0
1662+ _comp_expand_glob files ' /etc/sysconfig/network/ifcfg-*' || return 0
16631663 _comp_compgen -U files split -- " $( printf ' %s\n' " ${files[@]} " |
16641664 command sed -ne ' s|.*ifcfg-\([^*].*\)$|\1|p' ) "
16651665 elif [[ -f /etc/pld-release ]]; then
@@ -1668,8 +1668,7 @@ _comp_compgen_configured_interfaces()
16681668 command sed -ne ' s|.*ifcfg-\([^*].*\)$|\1|p' ) "
16691669 else
16701670 # Assume Red Hat
1671- _comp_expand_glob files ' /etc/sysconfig/network-scripts/ifcfg-*'
1672- (( ${# files[@]} )) || return 0
1671+ _comp_expand_glob files ' /etc/sysconfig/network-scripts/ifcfg-*' || return 0
16731672 _comp_compgen -U files split -- " $( printf ' %s\n' " ${files[@]} " |
16741673 command sed -ne ' s|.*ifcfg-\([^*].*\)$|\1|p' ) "
16751674 fi
@@ -1951,8 +1950,7 @@ _comp_compgen_xinetd_services()
19511950 local xinetddir=${_comp__test_xinetd_dir:-/ etc/ xinetd.d}
19521951 if [[ -d $xinetddir ]]; then
19531952 local -a svcs
1954- _comp_expand_glob svcs ' $xinetddir/!($_comp_backup_glob)'
1955- if (( ${# svcs[@]} )) ; then
1953+ if _comp_expand_glob svcs ' $xinetddir/!($_comp_backup_glob)' ; then
19561954 _comp_compgen -U svcs -U xinetddir -- -W ' "${svcs[@]#$xinetddir/}"'
19571955 fi
19581956 fi
@@ -2018,10 +2016,11 @@ _comp__init_set_up_service_completions()
20182016 local sysvdirs svc svcdir svcs
20192017 _comp_sysvdirs &&
20202018 for svcdir in " ${sysvdirs[@]} " ; do
2021- _comp_expand_glob svcs ' "$svcdir"/!($_comp_backup_glob)'
2022- for svc in " ${svcs[@]} " ; do
2023- [[ -x $svc ]] && complete -F _comp_complete_service " $svc "
2024- done
2019+ if _comp_expand_glob svcs ' "$svcdir"/!($_comp_backup_glob)' ; then
2020+ for svc in " ${svcs[@]} " ; do
2021+ [[ -x $svc ]] && complete -F _comp_complete_service " $svc "
2022+ done
2023+ fi
20252024 done
20262025 unset -f " $FUNCNAME "
20272026}
@@ -2355,8 +2354,7 @@ _comp_compgen_terms()
23552354 {
23562355 toe -a || toe
23572356 } | _comp_awk ' { print $1 }'
2358- _comp_expand_glob dirs ' /{etc,lib,usr/lib,usr/share}/terminfo/?'
2359- (( ${# dirs[@]} )) &&
2357+ _comp_expand_glob dirs ' /{etc,lib,usr/lib,usr/share}/terminfo/?' &&
23602358 find " ${dirs[@]} " -type f -maxdepth 1 |
23612359 _comp_awk -F / ' { print $NF }'
23622360 } 2> /dev/null) "
@@ -2455,9 +2453,8 @@ _comp__included_ssh_config_files()
24552453 i=" ${relative_include_base} /${i} "
24562454 fi
24572455 _comp_expand_tilde " $i "
2458- _comp_expand_glob files ' $REPLY'
2459- # In case the expanded variable contains multiple paths
2460- if (( ${# files[@]} )) ; then
2456+ if _comp_expand_glob files ' $REPLY' ; then
2457+ # In case the expanded variable contains multiple paths
24612458 for f in " ${files[@]} " ; do
24622459 if [[ -r $f && ! -d $f ]]; then
24632460 config+=(" $f " )
@@ -2592,8 +2589,7 @@ _comp_compgen_known_hosts__impl()
25922589 done
25932590 for i in /etc/ssh2/knownhosts ~ /.ssh2/hostkeys; do
25942591 [[ -d $i ]] || continue
2595- _comp_expand_glob tmpkh ' "$i"/*.pub'
2596- (( ${# tmpkh[@]} )) && khd+=(" ${tmpkh[@]} " )
2592+ _comp_expand_glob tmpkh ' "$i"/*.pub' && khd+=(" ${tmpkh[@]} " )
25972593 done
25982594 fi
25992595
0 commit comments