Opened 10 years ago
Closed 10 years ago
#44558 closed defect (invalid)
bash-completion on ssh hostname adds bad function, causes syntax errors
Reported by: | Daniel.Lipofsky@… | Owned by: | raimue (Rainer Müller) |
---|---|---|---|
Priority: | Normal | Milestone: | |
Component: | ports | Version: | 2.3.1 |
Keywords: | Cc: | ||
Port: | bash-completion |
Description
Initially this works:
~$ /opt/local/bin/bash -c "/bin/echo foobar" foobar ~$ /bin/bash -c "/bin/echo foobar" foobar ~$ /bin/sh -c "/bin/echo foobar" foobar
then I use ssh and I hit TAB to autocomplete the host name:
~$ ssh foo.example.com ... [me@foo ~]$ exit logout Connection to foo.example.com closed.
There when I run the same tests again I get an error
~$ /opt/local/bin/bash -c "/bin/echo foobar" /opt/local/bin/bash: _scp: line 28: syntax error near unexpected token `(' /opt/local/bin/bash: _scp: line 28: ` !(*:*)/* | [.~]*)' /opt/local/bin/bash: error importing function definition for `_scp' foobar ~$ /bin/bash -c "/bin/echo foobar" /bin/bash: _scp: line 28: syntax error near unexpected token `(' /bin/bash: _scp: line 28: ` !(*:*)/* | [.~]*)' /bin/bash: error importing function definition for `_scp' foobar ~$ /bin/sh -c "/bin/echo foobar" /bin/sh: _scp: line 28: syntax error near unexpected token `(' /bin/sh: _scp: line 28: ` !(*:*)/* | [.~]*)' /bin/sh: error importing function definition for `_scp' foobar
Removing the function definition clears the error
~$ unset -f _scp ~$ /opt/local/bin/bash -c "/bin/echo foobar" foobar ~$ /bin/bash -c "/bin/echo foobar" foobar ~$ /bin/sh -c "/bin/echo foobar" foobar
additional info
~$ uname -srvpoi Darwin 13.3.0 Darwin Kernel Version 13.3.0: Tue Jun 3 21:27:35 PDT 2014; root:xnu-2422.110.17~1/RELEASE_X86_64 i386 MacBookPro8,2 Darwin ~$ type -all bash; echo $BASH_VERSION; bash -version | grep version.*release bash is /opt/local/bin/bash bash is /bin/bash 4.3.18(1)-release GNU bash, version 4.3.18(1)-release (x86_64-apple-darwin13.2.0) ~$ port installed | grep -iE 'bash|complet|ssh|ssl' bash @4.3.18_0 (active) bash-completion @2.1_8 (active) curl @7.37.1_0+ssl (active) openssl @1.0.1h_0 (active) p5.16-io-socket-ssl @1.981.0_0 (active) p5.16-net-smtp-ssl @1.10.0_0 (active) p5.16-net-ssleay @1.580.0_0 (active) wget @1.15_1+ssl (active) wireshark @1.10.7_2+adns+geoip+gnutls+ipv6+libgcrypt+libsmi+lua+rtp+ssl+x11 (active)
Attachments (1)
Change History (16)
comment:1 Changed 10 years ago by Daniel.Lipofsky@…
Cc: | Daniel.Lipofsky@… added |
---|
comment:2 Changed 10 years ago by mf2k (Frank Schima)
Cc: | Daniel.Lipofsky@… removed |
---|---|
Keywords: | bash-completion ssh _scp removed |
Owner: | changed from macports-tickets@… to raimue@… |
In the future, please Cc the port maintainers (port info --maintainers bash-completion
). As reporter, you do not need to Cc yourself.
comment:3 Changed 10 years ago by Daniel.Lipofsky@…
There seems to be a similar error for RPM
/bin/sh: _rpm: line 93: syntax error in conditional expression: unexpected token `(' /bin/sh: _rpm: line 93: syntax error near `-@(*' /bin/sh: _rpm: line 93: ` if [[ ${words[@]} == *\ -@(*([^ -])f|-file )* ]]; then' /bin/sh: error importing function definition for `_rpm'
comment:4 Changed 10 years ago by raimue (Rainer Müller)
Somehow I can't reproduce this problem. I tried tab completion of hostnames for ssh with both a list presented and no list, but the test commands produced the same output as before and no error messages. I run bash as my login shell, but also testing in a newly spawned bash I can't reproduce it.
$ type _scp -bash: type: _scp: not found $ ssh foo.example.org<Tab> ... raimue@foo $ logout Connection to foo.example.org closed. $ type -t _scp function $ /opt/local/bin/bash -c "/bin/echo foobar" foobar $ /bin/bash -c "/bin/echo foobar" foobar $ /bin/sh -c "/bin/echo foobar" foobar $
$ port -q installed bash* and active bash @4.3.18_0 (active) bash-completion-devel @2.1_7 (active)
Changed 10 years ago by Daniel.Lipofsky@…
/opt/local/share/bash-completion/completions/ssh
comment:5 Changed 10 years ago by Daniel.Lipofsky@…
It's still a problem for me. I noticed you are using bash-completion-devel @2.1_7 while I am using bash-completion @2.1_8. I don't know if that could be the difference. Maybe compare to my _scp definition. I've attached the file that defines it and also pinter the definition from my bash shell.
$ find /opt/local/share/bash-completion/completions -xtype f | xargs -r grep -l '_scp()' | xargs -r ls -l lrwxr-xr-x 1 root admin 3 Apr 8 04:27 /opt/local/share/bash-completion/completions/autossh -> ssh lrwxr-xr-x 1 root admin 3 Apr 8 04:27 /opt/local/share/bash-completion/completions/scp -> ssh lrwxr-xr-x 1 root admin 3 Apr 8 04:27 /opt/local/share/bash-completion/completions/sftp -> ssh lrwxr-xr-x 1 root admin 3 Apr 8 04:27 /opt/local/share/bash-completion/completions/slogin -> ssh -rw-r--r-- 1 root admin 11766 Apr 8 04:27 /opt/local/share/bash-completion/completions/ssh $ type _scp _scp is a function _scp () { local cur prev words cword; _init_completion -n : || return; local configfile prefix; _ssh_suboption_check && { COMPREPLY=("${COMPREPLY[@]/%/ }"); return 0 }; case $prev in -l | -P) return 0 ;; -F | -i | -S) _filedir; compopt +o nospace; return 0 ;; -c) _ssh_ciphers; COMPREPLY=("${COMPREPLY[@]/%/ }"); return 0 ;; -o) _ssh_options; return 0 ;; esac; _expand || return 0; case $cur in !(*:*)/* | [.~]*) ;; *:*) _scp_remote_files; return 0 ;; esac; if [[ "$cur" == -F* ]]; then cur=${cur#-F}; prefix=-F; else set -- "${words[@]}"; while [[ $# -gt 0 ]]; do if [[ $1 == -F* ]]; then if [[ ${#1} -gt 2 ]]; then configfile="$(dequote "${1:2}")"; else shift; [[ -n $1 ]] && configfile="$(dequote "$1")"; fi; break; fi; shift; done; case $cur in -*) COMPREPLY=($( compgen -W '$( _parse_usage "${words[0]}" )' -- "$cur" )); COMPREPLY=("${COMPREPLY[@]/%/ }"); return 0 ;; */* | [.~]*) ;; *) _known_hosts_real -c -a -F "$configfile" "$cur" ;; esac; fi; _scp_local_files "$prefix"; return 0 }
comment:6 Changed 10 years ago by raimue (Rainer Müller)
bash-completion and bash-completion-devel are identical at the moment as there is no pre-release available. I checked that my /opt/local/share/bash-completion/completions/ssh
matches the file attached by you. Also the definition for _scp
is exactly the same in my shell.
From your command above, do you have /opt/local/libexec/gnubin
in your PATH? The options are not accepted that way by /usr/bin/xargs
or /usr/bin/find
. However, even when I add that to the front of my PATH I still can't reproduce the problem.
comment:7 Changed 10 years ago by Daniel.Lipofsky@…
yes
~$ echo $PATH /Users/danlip/bin:/opt/appmind/bin:/opt/java7/bin:/opt/local/libexec/gnubin:/opt/local/bin:/opt/local/sbin:/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin ~$ type -all xargs xargs is /opt/local/libexec/gnubin/xargs xargs is /usr/bin/xargs ~$ type -all find find is /opt/local/libexec/gnubin/find find is /usr/bin/find
comment:8 Changed 10 years ago by Daniel.Lipofsky@…
also I tried setting my PATH to just "/usr/bin" and I still see the error.
comment:9 Changed 10 years ago by larryv (Lawrence Velázquez)
Those fancy-pants patterns require extglob
to be enabled, which bash-completion does automatically when it’s sourced. So something is disabling it. Can you try this immediately after reproducing your problem?
$ bash -c 'shopt -s extglob && /bin/echo foobar'
comment:10 follow-up: 11 Changed 10 years ago by Daniel.Lipofsky@…
unfortunately that doesn't help (it was already set)
$ shopt extglob extglob on ~$ bash -c 'shopt -s extglob && /bin/echo foobar' bash: _scp: line 28: syntax error near unexpected token `(' bash: _scp: line 28: ` !(*:*)/* | [.~]*)' bash: error importing function definition for `_scp' foobar
comment:11 Changed 10 years ago by larryv (Lawrence Velázquez)
On second thought, that command doesn’t test anything; it’s not echo
that’s having a problem.
I think I know what’s going on. Which startup script do you source bash-completion from?
comment:12 follow-up: 13 Changed 10 years ago by Daniel.Lipofsky@…
I have the following in ~/.bash_profile
if [ -f /opt/local/etc/profile.d/bash_completion.sh ]; then source /opt/local/etc/profile.d/bash_completion.sh fi
comment:13 Changed 10 years ago by larryv (Lawrence Velázquez)
It looks like the child shells you’re running are inheriting the parent’s bash-completion functions, but they’re not sourcing bash-completion.sh
itself, which handles necessary setup like enabling extglob
. (Child shells do not inherit their parents’ options, so all the bash
invocations you’ve been testing with have extglob off
.)
At a quick glance, it doesn’t look like bash-completion exports its functions to the environment, so I don’t know why your functions are being inherited by child shells. You could try temporarily commenting out everything in your startup scripts except for the bash-completion bit and seeing whether that produces any results.
comment:14 Changed 10 years ago by Daniel.Lipofsky@…
Solved: my ~/.bash_profile was sourcing something that was sourcing something that was calling "set -a". It seemed to need it, but I was able to add a "set +a" at the end of my ~/.bash_profile to reverse it, which solved the problem.
comment:15 Changed 10 years ago by larryv (Lawrence Velázquez)
Resolution: | → invalid |
---|---|
Status: | new → closed |
Great!
Cc Me!