Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shopt failglob causes bash_completiion to give error in _included_ssh_config_files #705

Closed
idallen opened this issue Feb 23, 2022 · 1 comment · Fixed by #708
Closed
Assignees

Comments

@idallen
Copy link

idallen commented Feb 23, 2022

Describe the bug

Running the shell with shopt -s failglob causes the ssh config file glob expansion in _included_ssh_config_files() to fail with an error.

To reproduce

bash-5.0$ shopt -s failglob
bash-5.0$ ssh <TAB>bash: no match: /etc/ssh/ssh_config.d/*.conf

Expected behavior

Completion scripts should work without error even with failglob set.

Versions (please complete the following information)

  • [GNU/linux/Ubuntu 20.04.4 LTS] Operating system name/distribution and version:
  • [5.0.17(1)-release] bash version, echo "$BASH_VERSION":
  • [2.11.0] bash-completion version, (IFS=.; echo "${BASH_COMPLETION_VERSINFO[*]}"):

Additional context

Latest completion scripts downloaded via git clone and copied into Ubuntu.

Debug trace

+ _included_ssh_config_files /etc/ssh/ssh_config
+ (( 1 < 1 ))
+ local configfile i f
+ configfile=/etc/ssh/ssh_config
++ shopt -po noglob
+ local 'IFS= 
' 'reset=set -o noglob'
+ set -o noglob
+ included=($(command sed -ne 's/^[[:blank:]]*[Ii][Nn][Cc][Ll][Uu][Dd][Ee][[:blank:]]\(.*\)$/\1/p' "${configfile}"))
++ command sed -ne 's/^[[:blank:]]*[Ii][Nn][Cc][Ll][Uu][Dd][Ee][[:blank:]]\(.*\)$/\1/p' /etc/ssh/ssh_config
++ sed -ne 's/^[[:blank:]]*[Ii][Nn][Cc][Ll][Uu][Dd][Ee][[:blank:]]\(.*\)$/\1/p' /etc/ssh/ssh_config
+ local included
+ set -o noglob
+ [[ -n /etc/ssh/ssh_config.d/*.conf ]]
+ for i in "${included[@]}"
+ [[ /etc/ssh/ssh_config.d/*.conf =~ ^~.*|^/.* ]]
+ __expand_tilde_by_ref i
+ [[ /etc/ssh/ssh_config.d/*.conf == \~* ]]
+ set +o noglob
bash: no match: /etc/ssh/ssh_config.d/*.conf
@akinomyoga
Copy link
Collaborator

Thank you for the report and the debug trace. The error is caused by this line, where $i contains a glob pattern:

for f in $i; do

We need to enclose the glob expansion by shopt -s nullglob; shopt -u failglob. The following line also has a quoting problem:

_included_ssh_config_files $f

@akinomyoga akinomyoga self-assigned this Feb 24, 2022
akinomyoga added a commit that referenced this issue Apr 17, 2022
…fig_files

feat(_comp_expand_glob): Add a utility to safely perform pathname expansions (Fix #705)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants