ksh typeset is not returning value 0 while exiting from a POSIX function
Issue
- ksh typeset is not returning value 0 while exiting from a POSIX function
# cat ./a
#!/bin/ksh
# Sample script to demo ksh typeset problem.
# Set vars to global values...
X="X"
Y="Y"echo "X = $X" # value of var X, which should be "X".
echo "Y = $Y" # value of var Y, which should be "Y".GG() { # Define function named GG.
typeset Y # typeset var Y tobe local value only.
Y="Z" # Set function GG's var Y to "Z".
echo "X = $X" # value of var X, which should be "X".
echo "Y = $Y" # value of var Y, which should be "Z".
}GG # Call function GG
echo "X = $X" # value of var X, which should be "X".
echo "Y = $Y" # value of var Y, which should be "Y".
- The last line of above script, “Y =” should have value Y, not Z. But its giving "Z" value.
-
ksh typeset not keeping variables local within functions.
-
ksh typeset within functions are changing values of global variables outside of functions.
Environment
- Red Hat Enterprise Linux (RHEL) 5
- Red Hat Enterprise Linux (RHEL) 6
- Red Hat Enterprise Linux (RHEL) 7
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.