Score:1

Ubuntu 20.04: su command bash-autocomplete stopped working

jm flag

I am using Ubuntu 20.04. The su autocomplete stopped working. For example when I type:

su TabTab

It lists the files and directories of the current directory, where as it should list the available users.

Bash auto-complete for other commands is working fine for example:

apt-get TabTab

It lists the available apt-get options.

usermod TabTab

It lists the available user accounts.

su was working fine before and now it is not. I have no idea when it stopped working.

I have checked other questions but most of them are related to bash-completion, not specific to su. So, before marking it duplicate please check the existing answer if it addresses su.

Score:1
jm flag

Finally found the solution.

It is not an issue but due to the changes in the implementation of su command on Ubuntu-20.04.

Here is the workaround:

Edit the following file:

sudo vi /usr/share/bash-completion/completions/su

Replace line 44:

COMPREPLY=( $(compgen -f -- $cur) )

with

COMPREPLY=( $(compgen -u -- $cur) )

Source-1: https://stackoverflow.com/a/53417028/8388883

Source-2: https://github.com/scop/bash-completion/issues/253#issuecomment-440591431

The sources are for CentOS, but also working for Ubuntu 20.04.

Score:0
cn flag

In 20.04, you can use the following commands by default to make use of autocomplete:

sudo -u TabTab
su - TabTab
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.