What to do about typeset -L/-R combined with -i/-F/-E types?

17 views
Skip to first unread message

Martijn Dekker

unread,
Jun 28, 2020, 6:54:41 PM6/28/20
to Korn Shell
Community input is wanted on:
https://github.com/ksh93/ksh/issues/48

> This is not currently supported. See #47:
> https://github.com/ksh93/ksh/pull/47
>
> After applying #47, typeset -R10 -i foo=1; echo "[$foo]" gives a
> usage error and something like typeset -R10 -E3 foo=12345; echo
> "[$foo]" or typeset -R20 -F foo=12345; echo "[$foo]" simply ignores
> the -R flag.
>
> Which precedent should we follow? Maybe they should all error out? I
> think giving a usage error is more logical since this combination of
> flags is not actually possible. But it should be preceded by an
> informative error message such as "incompatible options
> combination".
>
> Or maybe we should just fix it so they can be combined? I see no real
> reason why this should be impossible. On mksh (which only supports
> integer arithmetic) the following works fine:
>
> $ mksh -c 'typeset -R10 -i foo=123 bar=4567; printf "%s\n" "[$foo]" "[$bar]"'
> [ 123]
> [ 4567]
>
> The other ksh-inspired shell that supports floating point arithmetic
> is zsh, and it has no problem combining any of these:
>
> $ zsh -c 'typeset -R20 -F foo=12345; echo "[$foo]"'
> [ 12345.0000000000]
> $ zsh -c 'typeset -R20 -E3 foo=12345; echo "[$foo]"'
> [ 1.23e+04]
> $ zsh -c 'typeset -R20 -i foo=12345; echo "[$foo]"'
> [ 12345]
>
> Community opinions invited. Should this be supported, or should it be
> an error, or should the -L/-R be ignored for these?

Feel free to respond to the list instead, I'll summarise any input given
here on the github issue.

- M.

--
|| modernish -- harness the shell
|| https://github.com/modernish/modernish
||
|| KornShell lives!
|| https://github.com/ksh93/ksh

Andras Farkas

unread,
Jun 28, 2020, 9:07:25 PM6/28/20
to Martijn Dekker, Korn Shell
On Sun, Jun 28, 2020 at 6:54 PM Martijn Dekker <mar...@inlv.org> wrote:
> Community input is wanted on:
> https://github.com/ksh93/ksh/issues/48

I'm not sure what the best path forward is, but, to offer a personal
anecdote: I remember a time I was trying to use typeset -Zi in a shell
script and being pretty confused before realising I had to use typeset
-Z alone. (though, that fact is explicitly mentioned in the man page
as "The -i attribute cannot be specified along with -R, -L, -Z, or
-f.")
I think the options of a useful error message ("-R and -i are
incompatible: consider using -R alone"?) or making them compatible are
both reasonable.
Reply all
Reply to author
Forward
0 new messages