Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In ~jacksonc/temp/ there are two files, test.txt and space test.txt, both placed there through Windows (using Samba).

Using bash, if I type

cat ~jacksonc/temp/t[tab]

, it autocompletes to

cat ~jacksonc/temp/test.txt

However, if I type

cat ~jacksonc/temp/s[tab]

it autocompletes to

cat /home/jacksonc/temp/space\ test.txt

My question isn't about the backslash, I know why that's there. I'm curious as to why the space causes the ~ to be expanded though?

share|improve this question
shrug it doesn't do the same thing for me (using bash 4.1.5 in Linux). It could just be a bug. – Flimzy Jul 6 '11 at 4:36
I doubt it. More likely it's a user setting, as Drav Sloan suggested. – Cam Jackson Jul 6 '11 at 5:11
Just to provide another data point, using the default settings on current Ubuntu, bash expands ~ to the actual path when using tab completion regardless of whether there's a space in the path or not. I have no idea why the space would make a difference either; I've never heard of such a thing before. – Dave Sherohman Jul 6 '11 at 8:11
Mmm. Unfortunately, I can't give too many details on the system I'm using, as my work uses its own internal Linux distribution, though I believe it's essentially re-badged Redhat from like, 6 years ago. – Cam Jackson Jul 6 '11 at 23:27
One extra thing though, is that ~ always expands upon tab-completion when in ksh, which is the default shell. But if I fire up bash it only happens with a space in the path. Weird. – Cam Jackson Jul 6 '11 at 23:34
up vote 4 down vote accepted

I would imagine because your system has bash_completion script installed, which can alter the behaviour of things like this.

Normally this expansion can be turned off via readline options. In your ~/.inputrc file put the following in it:

expand-tilde off
share|improve this answer
Hmm, maybe. I wouldn't know, I'm SSH'd into a server somewhere in this building. Any idea, though, why this happens only when a space is in the path? Doesn't make much sense to me. – Cam Jackson Jul 6 '11 at 5:19
I just checked, and there's no ~/.inputrc file in my home directory, so it's not this. It must be something similar though, seeing as different people are getting different results with ~ being expanded. – Cam Jackson Jul 8 '11 at 6:01
Well it's more that the ~/inputrc can effect the behaviour of this expansion. I personally suspect bash_completion (a set of autocomplete routines compiled to expand the default autocomplete of bash; it's an addition to the stand bash install. Signs of that are a directory /etc/bash_completion.d/ or a file /etc/bash_completion. – Drav Sloan Jul 9 '11 at 12:59
Accepting this answer. I don't think it's correct in the exact thing causing the effect (ie bash_completion), but most likely it's some other script doing the same thing. So this is correct in principle :) – Cam Jackson Jul 25 '11 at 5:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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