Well a very smart person told me to write a 10 line C program. Here it is.
#include <stdio.h>
#include <wordexp.h>
main(int argc, char **argv)
{
wordexp_t w;
char line[80];
while(gets(line)) {
wordexp(line, &w, 0);
printf("%s\n", w.we_wordv[0]);
wordfree(&w);
}
}
Create the two files abc and ab\d
Run the program and type in various strings.
Here is input and output.
jkl jkl
\\ \
\\\\ \\
ab? abc
ab\\e ab\e
ab\\* ab\* (should be ab\d)
ab\\$HOME ab\/home/eklhad
$HOME\\ab /home/eklhad/\ab
\\'j' \j
ab\\\\* ab\d
So backslashes are crunched once, and \' becomes ', and \| becomes |,
and so on as $variables are replaced.
Then, the next pass, globbing, if globbing occurs,
or if you want it to occur, then \\ becomes \ once again.
However \' does not become ', only \\ is crunched.
This second crunching is the bug, and there is really no way around it.
That's why ab\\\\* expands the way ab\\* should.
If I have the energy, and I'm not sure if I do,
but if I do, I believe the right answer is to write my own wordexp function
that does the following:
pass 1
ignore ' " | () [] ; \ blah blah blah,
no nasty side effects of calling this function.
No confusion, and no reason not to run it all the time.
don't have to start with a ` to invoke it, just run it because
it doesn't do anything weird.
Replace $var with its environment value,
and maybe even ${var}.
Let's be honest, this software is easy, and entirely portable.
pass 2
Call glob() to expand any shell wild cards.
This is the hard part, so let the library do that,
but glob doesn't screw up other characters in the string.
That's what I will sleep on tonight,
and see how I feel about it in the morning.
Karl Dahlke
_______________________________________________
Edbrowse-dev mailing list
[email protected]
http://lists.the-brannons.com/mailman/listinfo/edbrowse-dev