bug-bash
[Top][All Lists]
Advanced

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

Re: compgen gets confused when trying to complete ambiguous special char


From: Mika Fischer
Subject: Re: compgen gets confused when trying to complete ambiguous special char
Date: Tue, 18 Mar 2008 00:06:54 +0100
User-agent: Mutt/1.5.17+20080114 (2008-01-14)

* Chet Ramey <address@hidden> [2008-03-17 22:57]:
>> Can you elaborate on the differences in case they're the cause of other
>> strange behaviours?
>
> 1.  Backslashes should not be stripped within single quotes.
>
> 2.  Backslashes should only be stripped within double quotes if they're
>     followed by one of $ ` " \ <newline>

Ah, that's the reason for this behaviour then (using your quote func.):
address@hidden:~/rrr$ compgen -f $(quote "STORE")
STORE\'N\'GO
STORE'N'GO
address@hidden:~/rrr$ compgen -f $(quote "STORE'")
STORE'N'GO
address@hidden:~/rrr$ compgen -f $(quote "STORE\'")
address@hidden:~/rrr(1)$ compgen -f $(quote "STORE\\'")
address@hidden:~/rrr(1)$ compgen -f $(quote "STORE\\\'")
STORE\'N\'GO

So I guess I would not need the quote fuction but a function that quotes
the way compgen unquotes :)

I tried this and it seems to work:
quote2()
{
        local t=${1//\\/\\\\}
        echo \'${t//\'/\'\\\'\'}\'
}

address@hidden:~/rrr$ for i in test*; do echo -n "${i:0:5}: "; compgen -f
"$(quote2 "${i:0:5}")"; done
test`: test`test
test : test test
test': test'test
test": test"test
test$: test$test
test\: test\test

Something like this could be useful as a workaround for older versions
of bash. Comments?

> OK, I attached a patch.

On first sight this seems to work well:

address@hidden:~/rrr(1)$ compgen -f "STORE"
STORE\'N\'GO
STORE'N'GO
address@hidden:~/rrr$ compgen -f "STORE'"
STORE'N'GO
address@hidden:~/rrr$ compgen -f "STORE\'"
STORE\'N\'GO
address@hidden:~/rrr$ compgen -f "STORE\\'"
STORE\'N\'GO
address@hidden:~/rrr$ compgen -f "STORE\\\'"
address@hidden:~/rrr(1)$

address@hidden:~/rrr(1)$ for i in test*; do echo -n "${i:0:5}: "; compgen -f 
"${i:0:5}"; done
test`: test`test
test : test test
test': test'test
test": test"test
test$: test$test
test\: test\test

I'll test it a bit more tomorrow.

Thanks a lot for now!

Regards,
 Mika




reply via email to

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