A gotcha with Bash on Ubuntu 8.04

November 7, 2009

Suppose that you have an Ubuntu 8.04 system where you have opted to make /bin/sh be bash, the way it used to be in 6.06, and you have an account with /bin/sh as the login shell (for example, you created it with plain useradd). So you log in to the account and everything seems normal and bash-y, until you try to do filename completion and get:

$ cd /-sh: <( compgen -d -- '/' ): No such file or directory

(The text in bold is what you typed before you hit <TAB>.)

I'll give you the fix first: use chsh to change your shell to be /bin/bash. Then everything will work right.

This is one of those interestingly misleading error messages, although if you read very carefully Bash is actually sort of telling you what is going on. Let me give you a related example:

$ cat < 'a random name'
sh: a random name: No such file or directory

This error message has the same form as the first one but makes it much more obvious what the shell is complaining about.

For filename completion, what seems to be going on is that when Bash is operating in sh-compatible mode as a login shell, it is bash-like enough to cause the Ubuntu 8.04 default dotfiles to load the bash command line completion shell functions, but those functions use Bash-specific syntax. As a result, Bash in sh-compatible mode interprets the compgen command seen in the error message as one giant redirection and, of course, cannot find such a peculiarly named file.

(I spent a long time being confused by the error message because I didn't read it carefully and thus didn't realize that it was complaining about a failed redirection instead of a failure to find compgen.)

Short summary: this is an Ubuntu 8.04 bug caused by them not expecting /bin/sh to be Bash and to be used as a login shell, although this is a theoretically supported configuration. This doesn't really surprise me; we've had plenty of experience to the effect that Ubuntu goes off the rails when you depart from their one standard configuration.

Comments on this page:

From at 2009-11-07 04:03:17:

At one stage along the line Ubuntu switched from having /bin/sh symlinked to Bash to having it symlinked to Dash instead.

That's great for speed improvements but bad for all those badly written start up scripts that take advantage of stuff that's in bash but not dash, yet use /bin/sh instead of /bin/bash like they should do.

You should always point your script at the right shell if you want to reduce headaches. Numerous init scripts in Ubuntu had to be fixed after that symlink change. I remember it taking me an hour to figure out exactly why FreeRADIUS wasn't starting, and it was all down to the symlink.

Written on 07 November 2009.
« A shell script thing that I have learned the hard way
Solving unexposed types and the limits of duck typing »

Page tools: View Source, View Normal, Add Comment.
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Sat Nov 7 01:24:39 2009
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.