Bug 488943 - Defect in ksh emulation of zsh
Defect in ksh emulation of zsh
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: zsh (Show other bugs)
5.3
All Linux
high Severity high
: rc
: 5.4
Assigned To: James Antill
Branislav Náter
:
Depends On:
Blocks: 657300 688100
  Show dependency treegraph
 
Reported: 2009-03-06 06:30 EST by Darren Lavender
Modified: 2013-04-12 16:07 EDT (History)
4 users (show)

See Also:
Fixed In Version: zsh-4.2.6-5.el5
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 657300 688100 (view as bug list)
Environment:
Last Closed: 2010-10-27 12:19:15 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Darren Lavender 2009-03-06 06:30:13 EST
The ksh mode of zsh emits errors when it should not during a syntax only 
check, ie from the manual:

-n      Read commands and check them for syntax errors, but do not
execute  them.  Ignored  for  interactive shells.



# ksh --version    <------------------- RHEL version
  zsh 4.2.6 (i686-redhat-linux-gnu)

Also impacts latest upstream version:

[root@faraday zsh]# ./ksh --version  
zsh 4.3.9 (x86_64-unknown-linux-gnu)



Easily reproduced using the following abbreviated test case,  note the 
missing variable initialisation:


[root@faraday zsh]# more t.ksh
if [[ $(($v % 2)) == 1 ]]; then        
    a=ok
else
    a=nok
fi


Results:


### real ksh, syntax checking only, no problem (correct)
[root@faraday zsh]# ksh -n ./t.ksh    


### zsh, syntax checking only, problem (incorrect, bug)
[root@faraday zsh]# ./ksh -n ./t.ksh  
./t.ksh:1: bad math expression: operand expected at `% 2'  


### real ksh, complains at runtime (correct)
[root@faraday zsh]# ksh  ./t.ksh       
./t.ksh: line 1:  % 2: arithmetic syntax error


### zsh, also complains at runtime (correct)
[root@faraday zsh]# ./ksh  ./t.ksh  
./t.ksh:1: bad math expression: operand expected at `% 2'



This means that the second case (zsh -n flag) would appear to be in error, 
since syntactically speaking, the script is ok. The shell would _ONLY_ know
about the problem at runtime when the variable is checked/expanded. 

In other words, the zsh should not complain about the script when -n
flag is used (syntax check only), however it is _right_ to complain
about the script at runtime. 

This defect results in development compatibility issues across a heterogenous
environment using ksh scripts.
Comment 1 Darren Lavender 2009-03-06 06:35:13 EST
I forgot to add, the './ksh' is just linked to zsh in the above
test cases.
Comment 11 D Newport 2010-01-26 09:44:16 EST
You will also find it doesn't like this in the ksh compatibility mode of the zsh when using the -n option:

[[ -z ${XXX} ]] && exit 1

Although it is perfectly good syntax, the -n syntax checking option doesn't like it. A return code of 1 is returned from the script in which this code segment resides but there was no output to tell us what was wrong. We found this by trial and error, stripping the code down bit by bit.
Comment 21 errata-xmlrpc 2010-10-27 12:19:15 EDT
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2010-0804.html

Note You need to log in before you can comment on or make changes to this bug.