change in ksh typeset behavior

Solution Unverified - Updated -

Environment

  • Red Hat Enterprise Linux 6
    • ksh-20120801-10.el6.x86_64 (or later)

Issue

  • The effect of the following syntax on ENVIRONMENT VARIABLES is different in the new version of ksh (going from RHEL 6.4 to 6.5)

  • On Red Hat Enterprise Linux 6.4, ksh-20100621-19.el6_4.4.x86_64

    [root@base ~]# cat /etc/redhat-release 
    Red Hat Enterprise Linux Workstation release 6.4 (Santiago)
    
    [root@base ~]# rpm -qa | grep ksh-*
    ksh-20100621-19.el6_4.4.x86_64
    
    [root@base ~]# ksh
    
    # export AREA=${AREA:-gLoBaL}
    
    # print "ENV BEFORE: `env | grep AREA`"
    ENV BEFORE: AREA=gLoBaL
    
    # print "BLAH1 WXMAP.JOB AREA= ${AREA}"
    BLAH1 WXMAP.JOB AREA= gLoBaL
    
    #  typeset -l AREA=${AREA}
    
    # print "ENV AFTER: `env | grep AREA`"
    ENV AFTER: AREA=global                       <======== value is displaying
    A__z=( AREA="*SHLVL
    
    # print "BLAH2 WXMAP.JOB AREA= ${AREA}"
    BLAH2 WXMAP.JOB AREA= global
    
  • On Red Hat Enterprise Linux 6.5, ksh-20120801-10.el6_5.3.x86_64

    [root@vm201 ~]# cat /etc/redhat-release 
    Red Hat Enterprise Linux Server release 6.5 (Santiago)
    
    [root@vm201 ~]# rpm -qa | grep ksh-*
    ksh-20120801-10.el6_5.3.x86_64
    
    [root@vm201 manish]# ksh
    
    # export AREA=${AREA:-gLoBaL}
    
    # print "ENV BEFORE: `env | grep AREA`"
    ENV BEFORE: AREA=gLoBaL
    
    # print "BLAH1 WXMAP.JOB AREA= ${AREA}"
    BLAH1 WXMAP.JOB AREA= gLoBaL
    
    # typeset -l AREA=${AREA}
    
    # print "ENV AFTER: `env | grep AREA`"
    ENV AFTER:                                    <========= no value
    
    # print "BLAH2 WXMAP.JOB AREA= ${AREA}"
    BLAH2 WXMAP.JOB AREA= global
    

Resolution

  • The change in behaviour is actually a bug fix.
  • From the /usr/share/doc/ksh-20120801/RELEASE file

    12-04-27 A bug in which old attributes were not cleared when assigning a value using typeset has been fixed.

  • The correct way to achieve desired result is either to simply add the "tolower" attribute or to include an export attribute in the assignment variation

    typeset -l AREA
    typeset -lx AREA=${AREA}
    

Root Cause

  • The change in behaviour is actually a bug fix.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments