> However, a conforming implementation shall also permit 
> applications to specify the option and option-argument in the same argument 
> string without intervening <blank> characters."
> 
> How should ed interpret the following command line?:
> 
>    ed -p"" foo

Given how shells, exec() calls and the kernel pass arguments to a command,
such as ed, the ed command will see, in the above case, an argv[] of ["ed", 
"-p", "foo"].

In that case, either "foo" is the requested prompt (and no initial filename
to edit was provided), or the "-p" is lacking the requested prompt
(the empty "" having been lost along the way).

Since an invocation such as "ed -p Prompt: " is a legitimate and reasonable
invocation, therefore I would suggest that in the ed -p"" foo case, it be 
decided,
and perhaps documented, that the "-p" will always eat the next argument, empty
string or not, as the intended prompt, _unless_ a non-empty sequence of
characters follows the 'p' in that same argument.

This is consistent with what other commands do with similar option conventions.

For example, the command:
  df -B"" /
fails with:
  df: invalid -B argument '/'

whereas the command:
  df -B "" /
fails with:
  df: invalid -B argument ''

In both cases, the df -B command is looking for the first argv visible string,
whether a non-empty string attached to the -B argv[] parameter itself,
or in the next argv parameter, empty or not, and either way complaining
if that is not a legitimate string for the -B option.  

Since it is not possible for an exec'd Unix/Linux command to see
in the argv array passed to it whether or not an empty string was
appended to one of it's argv[] arguments when given to the exec'ing shell,
it makes sense to me to, and I understand to be the long standing
convention since the beginning of Unix shells in the 1970's,
to presume and behave as if no such invisible (to it) string existed,
anywhere, on any parameter in its argv[] array.

This convention is so deeply embedded in my bones for the last half
century that it did not occur to me when I first read *Emanuele* 
<mailto:torreemanue...@gmail.com>'s fine
report (and butchered my previous reply) that the ed command would
have any difficulty seeing the zero-length argv[] parameter following the
"-p" argument, and take that to be the requested prompt.

By the way, before the early 2000's Gnu rewrite, Bell Labs Unix and Linux "ed"
commands handled the empty "-p" prompt just fine, given, of course, that
the "" empty prompt is provided in a separate argv[] parameter following
the "-p" (for that is and forever has been the only way to pass an empty 
parameter).

-- 
  Paul Jackson
  jack...@fastmail.fm


Reply via email to