I'm using Ubuntu 14.04.5 LTS.

The ssh bash completion on any Host of the file ~/.ssh/config does not work :

$ ssh b2sed: -e expression #1, char 97: invalid reference \2 on `s' command's RHS

The package for the ssh completion, is already installed :

$ dpkg -S /usr/share/bash-completion/completions/ssh
bash-completion: /usr/share/bash-completion/completions/ssh
  • @Kusalananda Thanks, I have just seen that sed is aliased to \sed -E on my system. I'm searching where in the bash-completions scripts, this particular sed call is done ... – SebMa Feb 23 at 17:48
  • @Kusalananda I found a way but I think it is not recommanded, please see my EDIT1 – SebMa Feb 23 at 18:02
  • 2
    You should submit a bug report so that it's fixed in the bash-completion package. Your fix is correct and what the function should have used from the start. – Kusalananda Feb 23 at 18:35

I found that on my system, sed is aliased to sed -E

So instead of removing this alias which I use quite a lot actually, I decided to update the _known_hosts_real function in the /usr/share/bash-completion/bash_completion script (which I think is not really recommanded) :

$ type _known_hosts_real | grep -w sed
        local hosts=$( sed -ne 's/^[ \t]*[Hh][Oo][Ss][Tt]\([Nn][Aa][Mm][Ee]\)\{0,1\}['"$'\t '"']\{1,\}\([^#*?]*\)\(#.*\)\{0,1\}$/\2/p' "${config[@]}" );

by replacing sed -ne by command sed -ne, this way :

# append any available aliases from config files
if [[ ${#config[@]} -gt 0 && -n "$aliases" ]]; then
    local hosts=$( command sed -ne 's/^[ \t]*[Hh][Oo][Ss][Tt]\([Nn][Aa][Mm][Ee]\)\{0,1\}['"$'\t '"']\{1,\}\([^#*?]*\)\(#.*\)\{0,1\}$/\2/p' "${config[@]}" )
    COMPREPLY+=( $( compgen -P "$prefix$user" \
        -S "$suffix" -W "$hosts" -- "$cur" ) )

However, those changes are going to be lost when the bash-completion package gets updated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.