Steps to reproduce the problem:
$ mkdir a\'b
$ touch a\'b/{c,d}
$ compgen -f a\'b/
$
Expected output:
a\'b/c
a\'b/d
Freddy Vulto
http://fvue.nl
Same behavior with a double quote.
However, with quoting, these work:
compgen -f "a\'b/"
compgen -f 'a\"b/'
or using a variable:
dir="a\'b/"; compgen -f $dir
Both do not work at my machine? Are you sure you don't have a directory
`ab' besides `a\'b'? That's whap happened to me too...
It seems compgen is leaving out the quote out erroneously:
$ mkdir a\'b
$ touch a\'b/c
$ mkdir ab
$ touch ab/e
$ compgen -f a\'b/
ab/e # Should be a\'b/c
Freddy Vulto
http://fvue.nl
$ ls -ld a*b
ls: cannot access a*b: No such file or directory
$ mkdir a\'b
$ touch a\'b/c
$ compgen -f a\'b/
$ compgen -f "a\'b/"
a\'b/c # correct
$ mkdir ab
$ touch ab/e
$ compgen -f "a\'b/"
a\'b/c # correct
$ compgen -f a\'b/
a\'b/e # INcorrect
$ echo $BASH_VERSION # Ubuntu 9.10
4.0.33(1)-release
However I just tested it under Cygwin with Bash 3.2.49(23)-release and
got these results similar to yours:
$ ls -ld a*b
ls: cannot access a*b: No such file or directory
$ mkdir a\'b
$ touch a\'b/c
$ compgen -f a\'b/
$ compgen -f "a\'b/"
$ mkdir ab
$ touch ab/e
$ compgen -f "a\'b/"
a\'b/e # INcorrect
$ compgen -f a\'b/
ab/e # INcorrect
Here, the quotes didn't give the correct results, but gave different
incorrect ones.
$ echo $BASH_VERSION
4.0.35(2)-release
$ ls a*b # Make sure there's no `ab' directory
ls: cannot access a*b: No such file or directory
$ mkdir a\'b; touch a\'b/c
$ mkdir ab; touch ab/d
$ compgen -f a\'b/
ab/d # INcorrect
$ compgen -f a\\\'b/
a\'b/c # correct
I found on bash-3 the workaround is to double(triple?)-escape the quotes:
$ echo $BASH_VERSION
$ ls a*b # Make sure there's no `ab' directory
ls: cannot access a*b: No such file or directory
$ mkdir a\'b; touch a\'b/c
$ mkdir ab; touch ab/d
$ compgen -f a\'b/
ab/d # INcorrect
$ compgen -f a\\\'b/
a'b/d # INcorrect?
$ compgen -f a\\\\\'b/
a\b/d # INcorrect
$ compgen -f a\\\\\\\'b/
a\'b/d # correct
$ compgen -f "a\\\\\'b/"
So, these are the workarounds:
$ ls a\'b/ # For reference, works on both bash-3 & bash-4
c
$ compgen -f a\\\'b/ # Workaround for bash-4
a\'b/c
$ compgen -f a\\\\\\\'b/ # Workaround for bash-3
a\'b/c
Regards,
Freddy Vulto
http://fvue.nl
The last time this came up, I wrote:
For historical reasons, complete/compgen dequote the filename they're
passed, removing backslash escapes and interpreting embedded quoted
substrings. (One of the things bash should do when it does that is to
be better about obeying the shell rules about backslash-escaped characters
and double quotes, but that doesn't matter for this example -- though that
function has several problems.)
When it's called as the result of readline dispatching on a particular
character, this is appropriate -- the shell hasn't done any expansion
or quote removal, so the filenames still have embedded quoting. When
called from the command line, as in these examples, it's not appropriate,
since the shell has already expanded the argument and stripped the
quotes.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU ch...@case.edu http://cnswww.cns.cwru.edu/~chet/