sqweek:
> It seems to me the obvious way to gain consistency is to do the list parsing
> in one place only:
hi sqweek,
Thanks for the thoughtful response. You are right, it could be fixed with
another tool like xargs. I wrote a similar tool "modify" which I use to modify
files in place with standard tools, like `modify nl : a b c` to number lines in
three files. Given that nearly all the tools do already handle lists of
arguments (wrongly), I saw a need to correct them.
Plan 9 tools that accept options already do accept `--' to mark the end of
options and the start of proper arguments, it is a necessary feature.
I will show what sort of change would be needed for grep. I have not looked at
the source for plan 9 grep, so this is just an example.
If the existing code was:
char *pattern;
int use_stdin, prefix_filename;
...
if strcmp(argv[i], "--") == 0
...
...
pattern = argv[0]; ++argv; --argc;
use_stdin = !argc;
prefix_filename = argc > 1;
The changed code would be:
char *pattern;
int dwim, use_stdin, prefix_filename;
dwim = 1;
...
if strcmp(argv[i], "--") == 0
dwim = 0
...
...
pattern = argv[0]; ++argv; --argc;
use_stdin = dwim && !argc;
prefix_filename = !dwim || argc > 1;
The difference from current logic is very slight. It's not rocket science.
Then something like:
grep foo -- `{find ...}
would work correctly and consistently.
grep foo -- *
will still not work because rc's globbing also fears zero and returns the
pattern instead of an empty list if there are no matches.
Sam