From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Mon, 5 Oct 2009 16:54:23 +1100 From: Sam Watkins To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Message-ID: <20091005055423.GA14691@nipl.net> References: <20091003191118.GD15021@nipl.net> <45a41ae73e4adf6d1b38fe9c31977c52@proxima.alt.za> <20091004071748.GA16895@nipl.net> <140e7ec30910040359q28c30ea2re5185846042cf43a@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <140e7ec30910040359q28c30ea2re5185846042cf43a@mail.gmail.com> User-Agent: Mutt/1.5.13 (2006-08-11) Subject: Re: [9fans] mishandling empty lists - let's fix it Topicbox-Message-UUID: 7e332230-ead5-11e9-9d60-3106f5b1d025 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