Jean Delvare dixit:

>On Fri, 10 Feb 2017 13:10:20 +0000 (UTC), Thorsten Glaser wrote:
>> That’s ksh88 where you(r customer) come(s) from?
>
>Our previous products included ksh93.

OK. (Found out as well that ksh93 has print -e, which we had code
for but no member in the getopt call…)

>> >> We have the echo you mean in POSIX mode though…
>> >
>> >Not sure what you mean here. I see that the echo command behavior is
>> >changed if Flag(FPOSIX), but I can't seem to be able to set that flag
>> >(I tried "export POSIX=1" but that doesn't seem to change anything?)
>>
>> “set -o posix” ;-)

Turns out that there is no evidence that “BSD echo” ever was
anything else than what POSIX documents:

if test x"$1" = x"-n"; then
        shift
        printf "%s" "$*"
else
        printf "%s\n" "$*"
fi

This e̲x̲a̲c̲t̲l̲y̲ matches our “set -o posix” echo builtin, which
actually specifies more than POSIX “echo” does, and conforms
to Debian Policy §10.4 as well. I have renamed the code path
“BSD echo” now, and the default/other one “compromise echo”,
possibly with the MidnightBSD (and FreeBSD) /bin/sh-specific
kludge of defaulting to -E but supporting -Een still.

(Our default “echo” implements XSI escapes but violates POSIX
in that it d̲o̲e̲s̲ support options, matching historic practice.)

>> >caveat: -E would be handled as a valid option, while it was not
>>
>> True, but that can be circumvented.
>
>Sure it can. My patch was more of a proof-of-concept (one of many, I
>tried different approaches before) and details can be discussed.

I looked at ksh93 and investigated several approaches and ended
up codifying “as soon as -R is encountered, we jump into the BSD
echo (formerly called Debian echo) codepath”.

This matches ksh93 in that things like a previous -n, -uN, -s, …
are *not* reset:

tg@blau:/usr/src/bin/mksh $ obj/mksh -c 'print -u2 -R -42' >/dev/null
-42

This allows your use cases:

tg@blau:/usr/src/bin/mksh $ obj/mksh -c 'print -R -n -4; print -R 2'
-42

Parsing after -R like ksh93 does is not supported:

tg@blau:/usr/src/bin/mksh $ ksh93 -c 'print -Rn foo; print bar'
foobar
tg@blau:/usr/src/bin/mksh $ obj/mksh -c 'print -Rn foo; print bar'
foo
bar

But:

tg@blau:/usr/src/bin/mksh $ obj/mksh -c 'print -R -n foo; print bar'
foobar


This will be in the next mksh release.

Thanks,
//mirabilos
-- 
“It is inappropriate to require that a time represented as
 seconds since the Epoch precisely represent the number of
 seconds between the referenced time and the Epoch.”
        -- IEEE Std 1003.1b-1993 (POSIX) Section B.2.2.2

Reply via email to