Bug 488943 - Defect in ksh emulation of zsh
Summary: Defect in ksh emulation of zsh
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: zsh
Version: 5.3
Hardware: All
OS: Linux
high
high
Target Milestone: rc
: 5.4
Assignee: James Antill
QA Contact: Branislav Náter
URL:
Whiteboard:
Depends On:
Blocks: 657300 688100
TreeView+ depends on / blocked
 
Reported: 2009-03-06 11:30 UTC by Darren Lavender
Modified: 2018-11-14 18:23 UTC (History)
4 users (show)

Fixed In Version: zsh-4.2.6-5.el5
Doc Type: Bug Fix
Doc Text:
Clone Of:
: 657300 688100 (view as bug list)
Environment:
Last Closed: 2010-10-27 16:19:15 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2010:0804 0 normal SHIPPED_LIVE zsh bug fix update 2010-10-27 16:19:10 UTC

Description Darren Lavender 2009-03-06 11:30:13 UTC
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 11:35:13 UTC
I forgot to add, the './ksh' is just linked to zsh in the above
test cases.

Comment 11 D Newport 2010-01-26 14:44:16 UTC
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 16:19:15 UTC
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.