I just set up a VPS with hostinger.com. The OS is Ubuntu 18.04. I created a user account, mike. I quickly realised that auto-completion wasn't apparently installed so looked up how you do this. For some reason (type of shell?) I have to source with a dot, not with the word source.

Logged in as mike I did this:

sudo apt-get install bash-completion

(NB trying to solve the problem I later tried sudo apt-get install --reinstall bash-completion)

... and I added this line to /home/mike/.bashrc:

. /etc/bash_completion

In fact this file consists of one line:

. /usr/share/bash-completion/bash_completion

The situation currently is that I can get auto-completion working when logged in as root, by doing this:

$ . /home/mike/.bashrc

But when logged in as mike the same command gives:

$ . /home/mike/.bashrc
-su: 26: /usr/share/bash-completion/bash_completion: Syntax error: "(" unexpected

Searching for answers I surmised that the problem might be caused by an alias conflict. But now there are no aliases when logged in as mike and yet the problem persists.

I'm trying (among other things) to understand what "-su: 26" actually means. This appears to be a line reference. But line 26 of that file is in fact blank.

What I'm now thinking of doing is to go through /usr/share/bash-completion/bash_completion, commenting out lines until things start to make sense. But it's a big file!

Obviously one curious aspect of this is that it works when I'm logged in as root but not when logged in as mike.

I scp'd my bash_completion file in my local machine to the VPS and used it to replace the existing one (renamed the latter first). Again, sourcing when root worked OK. Again, sourcing when logged in as mike produced (several) errors:

$ . /home/mike/.bashrc
-su: 29: /usr/share/bash-completion/bash_completion: [[: not found
-su: 35: /usr/share/bash-completion/bash_completion: [[: not found
-su: 51: /usr/share/bash-completion/bash_completion: shopt: not found
-su: 57: /usr/share/bash-completion/bash_completion: complete: not found
-su: 62: /usr/share/bash-completion/bash_completion: complete: not found
[... more... ]

Any suggestions? Might it be that the mike account is for some reason using a different shell? A different shell grammar? How might I check this sort of thing?

  • Is the mike user using bash as its shell? If you are using another shell, such as zsh and not bash, you may encounter these kind of problems. Please run the following getent passwd mike and getent passwd root and report back on what they output. Importantly, look at the last field, which is the "user command interpreter" or what shell that user runs when logged in.
    – ender.qa
    Dec 1 '19 at 23:29

(logged in as root:)

root@vps46990199:~# getent passwd mike
root@vps46990199:~# getent passwd root

... a little searching finds the answer:

root@vps46990199:~# usermod -s /bin/bash mike

... problem solved (thanks to ender.qa)

more info
Reading around, I first verify that in fact /bin/sh is not a file but a symlink. In accordance with modern versions of Ubuntu this was (before I ran usermod) linking to /bin/dash, about which I read:

bash is a de facto standard (very widely used) but it is not "standard"; sh on Ubuntu uses dash, which is a Posix-compliant shell, so it is really standard. My advice is to use dash as often as possible for scripting, especially for server-side scripts. Although bash is more expressive, dash runs quite a lot faster and is more secure (here, comment by Rick-777)

Which makes you wonder why Hostinger.com's root account uses bash rather than dash as standard, as with a default created user account. Beyond my paygrade.

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.