bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Strange compgen behaviour


From: Mathias Dahl
Subject: Strange compgen behaviour
Date: Tue, 22 Sep 2009 15:14:21 -0700 (PDT)
User-agent: G2/1.0

Hi fellow bashers!

I am trying to add some completion to a command. The completion should
list all movies I have in a certain folder, regardless if I am in that
folder or not. I have kind of got it to work in several variants but
all have some issue. The current problem I am looking at is very
strange. I have isolated it down to a strange behaviour with compgen.
Let's see if I can describe it clearly enough:

zf contains the list of movie file names
zc is the current input, in my case "/home/mathias/Videos/movies/H"

$ compgen -W "${zf}" -- ${zc}

Here is the output:

/home/mathias/Videos/movies/Harry.Potter...
/home/mathias/Videos/movies/Harry.Potter...
/home/mathias/Videos/movies/Harry.Potter...
/home/mathias/Videos/movies/Harry.Potter...
/home/mathias/Videos/movies/Harry.Potter...
/home/mathias/Videos/movies/Brazil (Terry Gilliam, 1985).avi
/home/mathias/Videos/movies/Ice.Age.2...
/home/mathias/Videos/movies/True.Blood.S01...
/home/mathias/Videos/movies/True.Blood.S01...

I have shortended the names to make it more readable and also removed
some hits.

The main issue here is how for example the line with Brazil can match
the input. Same goes for True Blood. And, to make it even more scary,
an input such as "/home/mathias/Videos/movies/B" does not match the
Brazil line.

What's up with this?

My bash version:

$ bash --version
GNU bash, version 3.2.39(1)-release (i486-pc-linux-gnu)

Running under Ubuntu 8.04.

Thanks!

/Mathias

PS. If you like I can post the whole function that takes care of the
completion, but I think it is not important here.

PPS. The main cause of the issues I have seens to be that some file
names have spaces, and as I said earlier, every way I have tried, even
the ones that workes so so, have some issues. Any tips to get this
relatively fool proof?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]