ksh regression wrong return code from a function

Solution Verified - Updated -

Issue

  • Under some circumstances, one gets an incorrect return code from a function.
  • Refer Test script:
#!/bin/ksh

foo() {
  z=shift
  print -r $z | read
  return 1
}

bar() {
  z=shift
  print -r $z | read
  cat /dev/null
  return 1
}

out=$(foo "foo")
res=$?
echo Res is: $res

out=$(bar "bar")
res=$?
echo Res is: $res


[root@localhost ~]# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 6.4 (Santiago)
[root@localhost doug]# rpm -qa ksh
ksh-20100621-19.el6_4.4.x86_64
[root@localhost doug]# ksh --version
  version         sh (AT&T Research) 93t+ 2010-06-21
[root@localhost doug]# vi testscript.sh
[root@localhost doug]# chmod 755 testscript.sh 
[root@localhost doug]# su - doug
[doug@localhost ~]$ ./testscript.sh 
Res is: 1
Res is: 1
[doug@localhost ~]$ exit
logout
[root@localhost doug]# 

[root@localhost doug]# ls
ksh-20120801-10.el6_5.6.x86_64.rpm  testscript.sh
[root@localhost doug]# rpm -q ksh
ksh-20100621-19.el6_4.4.x86_64
[root@localhost doug]# rpm -e ksh-20100621-19.el6_4.4       
[root@localhost doug]# rpm -ivh ksh-20120801-10.el6_5.6.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:ksh                    ########################################### [100%]
[root@localhost doug]# 
[root@localhost doug]# ksh --version
  version         sh (AT&T Research) 93u+ 2012-08-01
[root@localhost doug]# 
[root@localhost doug]# su - doug
[doug@localhost ~]$ ./testscript.sh 
Res is: 0                       <============wrong value
Res is: 1
[doug@localhost ~]$ 

Environment

  • ksh-20120801-10.el6_5.6.x86_64
  • Red Hat Enterprise Linux

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content