Sujet : Re: [ksh93u+m] Performance warning message
De : martijn (at) *nospam* inlv.demon.nl (Martijn Dekker)
Groupes : comp.unix.shellDate : 03. Nov 2024, 18:29:02
Autres entêtes
Message-ID : <lopq6uF6mbkU1@mid.individual.net>
References : 1 2
User-Agent : Mozilla Thunderbird
Op 28-10-2024 om 00:21 schreef Janis Papanagnou:
On 25.10.2024 06:46, Janis Papanagnou wrote:
[...]
(( typeset -i indents = level * indent_factor ))
>
(I wasn't aware about the 'typeset' command possible in arithmetic
expressions.)
Oops! - That's wrong. - I had just tested that only with 'ksh -n'.
ksh -n had produced the above performance warning message, but it
did not produce an error message for the (( typeset ... )) syntax,
which I saw just now when invoking the shell regularly on the code.
This is really odd (shell-)behavior! (Reporting a warning but not
an error.) - Looks like a bug to me.[*]
C-style shell arithmetic is treated as mostly separate from the shell language proper. As far as the shell language is concerned, an arithmetic expansion or command is just a glorified quoted string. So, they are parsed separately from the shell language, and both parsing and executing happens at runtime. This means shell arithmetic syntax errors can only be detected while executing the script, i.e., not when using noexec. All the POSIX-based shells are the same in that, because they all copied ksh's design for shell arithmetic.
[*] The man page says for option '-n':
"Read commands and check them for syntax errors, [...]"
So the warning message is just an undocumented feature for free?
Yes. The -n (noexec) option activates a (very limited) linter mode that produces certain warnings. The arithmetic-related linter warnings don't look at the arithmetic expression itself at all, but only at the shell grammar context in which an arithmetic expression is used.
-- || modernish -- harness the shell|| https://github.com/modernish/modernish|||| KornShell lives!||
https://github.com/ksh93/ksh