This Ubuntu machine is showing errors when I start a new terminal. The problem is this:

When bash completion is sourced (. /usr/share/bash-completion/bash_completion) the shell taking place is not bash and some variable definitions with lists local words=() is failing (because only bash understands lists).

My solution was to explicitly call with bash /usr/share/bash-completion/bash_completion, but I'd like to know why another shell is being called when I open terminal. I thought that, since bash is my default, that it would also be used during sourcing.

I've done a echo $0 just before calling the bash-completion file and the output is bash.

What would cause bash not to be used for sourcing?

Addressing questions from comments:

This happens when I start a new console, which means that the kernel will start a new terminal window, calling the ~/.profile, which in its turn do a . "$HOME/.bashrc", which will in its turn source the bash completion (. /usr/share/bash-completion/bash_completion)

I don't have a ~/.bash_completion file.

I can't put the echo "$0" to inside of the bash_completion because it will fail and not be executed.

My .bashrc and .profile are the default ones that come with Ubuntu. I don't have a .bash_profile. You can find them in your local Ubuntu 14.04 under /etc/skel/

  • Please edit your question and explain i) where the source command is. What file? When is it run? ii) if this is a script, show us the script. – terdon May 11 '15 at 16:21
  • Try adding set -x before you source that file. Do you see anything odd? – glenn jackman May 11 '15 at 16:31
  • Do you have a ~/.bash_completion file? – glenn jackman May 11 '15 at 16:32
  • If you want to change your default shell, use the chsh command like so : chsh -s bash. Also, note that sometimes the terminal emulator you use can start a new shell by its own. For instance, in konsole, my default profile starts bash by default (I therefore use bash locally) but I had to use chsh so that my shell would be bash also when I use ssh. – user43791 May 11 '15 at 17:20
  • @user43791 my chsh points to /bin/bash. That is the default. I just checked and it hasn't changed. I don't want to change my default shell, I am trying to find out why would Ubuntu decide to change it to sh instead of bash. – Alexandre Santos May 11 '15 at 20:36

The problem wasn't the shell or chsh or anything exotic. It was a stupid alias on local. Someone thought it was a good idea to create an alias that displays the local ip address, and named it "local", so the line

local cword words=()

was failing not because the shell couldn't handle arrays. It failed because the alias was expanding and the () didn't make sense there.

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.