Re: compgen -f failing on directory containing single quote
On 12/13/09 5:07 AM, Freddy Vulto wrote: > `compgen -f' produces no output if the directory contains a single quote. > I get the same result on both bash-3.2.39 and bash-4.0.35. > > 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 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, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/
Re: compgen -f failing on directory containing single quote
On 091213 08:34, DennisW wrote: Thanks for testing. Indeed on bash-4 quoting works for me as well. Adding additional backslashes works also on bash-4: $ 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
Re: compgen -f failing on directory containing single quote
On Dec 13, 8:17 am, Freddy Vulto wrote: > On 091213 05:13, DennisW wrote: > > > 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 Vultohttp://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.
Re: compgen -f failing on directory containing single quote
On 091213 05:13, DennisW wrote: > 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
Re: compgen -f failing on directory containing single quote
On Dec 13, 4:07 am, Freddy Vulto wrote: > `compgen -f' produces no output if the directory contains a single quote. > I get the same result on both bash-3.2.39 and bash-4.0.35. > > 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 Vultohttp://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
compgen -f failing on directory containing single quote
`compgen -f' produces no output if the directory contains a single quote. I get the same result on both bash-3.2.39 and bash-4.0.35. 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