Deutsch   English   Français   Italiano  
<lopq6uF6mbkU1@mid.individual.net>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: Martijn Dekker <martijn@inlv.demon.nl>
Newsgroups: comp.unix.shell
Subject: Re: [ksh93u+m] Performance warning message
Date: Sun, 3 Nov 2024 17:29:02 +0000
Lines: 40
Message-ID: <lopq6uF6mbkU1@mid.individual.net>
References: <vff7qe$31ohp$1@dont-email.me> <vfmldv$ll5i$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net kF3Wm/ACUhAs65JM6YEl7wUJsXVmdLfrrihZf0sQjDfc3OCFw=
Cancel-Lock: sha1:+UEMdbYNFDaAF9k7hHNWkAz7NSc= sha256:KqUEBJbYMwvRhIWt01qSScUKBUZkIeL9sHjNU2qqnzo=
User-Agent: Mozilla Thunderbird
Content-Language: en-GB
In-Reply-To: <vfmldv$ll5i$1@dont-email.me>
Bytes: 2619

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