3

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?

6
  • 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, 2011 at 4:36
  • I doubt it. More likely it's a user setting, as Drav Sloan suggested. Jul 6, 2011 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. Jul 6, 2011 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. Jul 6, 2011 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. Jul 6, 2011 at 23:34

1 Answer 1

4

I would imagine because your system has bash_completion script http://bash-completion.alioth.debian.org/ 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
4
  • 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. Jul 6, 2011 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. Jul 8, 2011 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, 2011 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 :) Jul 25, 2011 at 5:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .