If fLogOpen is called before fSendReqToSvr then fSendReqToSvr does not return anything, it writes the contents of the local variable ToDo into the log file. So the expected behavior is that in fGetFileStatusFromSvr ToDo is overwritten with an empty string.
In ksh88 the exec 3>logfile may have failed if logfile exists and noclobber is active. Then exec 1>&3 fails as well and stdout is not redirected. In ksh93 fd3 is present in any case, so the print "ToDo" is not propagated to the calling context. Try print ... >&4 home> /bin/ksh -c 'ls -l /proc/$$/fd' total 0 lrwx------ 1 yae5511 yae55 64 May 21 15:15 0 -> /dev/pts/1 lrwx------ 1 yae5511 yae55 64 May 21 15:15 1 -> /dev/pts/1 lrwx------ 1 yae5511 yae55 64 May 21 15:15 2 -> /dev/pts/1 lr-x------ 1 yae5511 yae55 64 May 21 15:15 3 -> /proc/28152/fd home> /bin/pdksh -c 'ls -l /proc/$$/fd' total 0 lrwx------ 1 yae5511 yae55 64 May 21 15:16 0 -> /dev/pts/1 lrwx------ 1 yae5511 yae55 64 May 21 15:16 1 -> /dev/pts/1 lrwx------ 1 yae5511 yae55 64 May 21 15:16 2 -> /dev/pts/1 Mit freundlichen Gruessen / Best Regards Axel Dr. rer. nat., Dipl. Phys. MTU Aero Engines AG Informationswirtschaft/Entwicklungssysteme (POE) Information Management/Engineering Systems (POE) Dachauer Str. 665 80995 Muenchen Germany Von: [email protected] [mailto:[email protected]] Im Auftrag von Welling, Gerhart G. Gesendet: Montag, 19. Mai 2014 22:39 An: [email protected] Betreff: [ast-users] Korn Shell 93 - Some Values Returned by Function are Empty String, But Contained Value in Function Readers: I'm writing in regard to ksh scripts I wrote to the ksh88 standards which have run for years on many HP-UX/PA-RISC and Solaris/Sparc platforms, and, even a few Linux/x86_64) platforms ... until this week. Upon running the scripts on CentOS 6.4/x86-x64 with Korn shell "Version AJM 93u+ 2012-08-01", non-null values being returned to a calling function are sometimes retrieved by the caller as null values. Specifically, in the edited excerpts following, the variable ToDo always contains a value in fSendReqToSvr prior to fSendReqToSvr returning. When fSendReqToSvr returns in fGetFileStatusFromSvr, Todo is often assigned a null value. The context of this script is as a child invoked by another ksh script run from cron. I've included the code reassigning stdout and stderr on the chance this is somehow significant. What don't I understand? OS: CentOS-6.4 (x86-64) Development Installation Korn Shell: Version: AJM 93u+ 2012-08-01 Package: Ksh.x86_64 20120801-10.el6 ... function fLogOpen { ... exec 3>$1 #C# Assigned Fd 3 to a log file #C# stdout and stderr are redirected to log file as insurance that #C# no "errant" output from script (1700 lines) "escapes" from script. #C# stdout and stderr restored in fLogClose. exec 4>&1 exec 1>&3 exec 5>&2 exec 2>&3 ... } ... #C# Invokes curl on behalf of caller and evaluates the outcome, returning #C# a string specifying what the caller should do. function fSendReqToSvr { typeset Err=0 ... \ ToDo=CONTINUE ... \ CL="$2" ... Typeset -I iSecsLeft=$1 iSleepSecs=3 ... curl $CL > $CurlOutFFS 2>&1 & gCurlPId=$! while (( iSecsLeft > 0 )) ; do ... #C# Sleep N secs, check status of curl with "kill -0 $gCurlPId" #C# and if curl exited, get return code from "wait $gCurlPId". ... (( iSecsLeft = iSecsLeft - iSleepSecs )) done ... #C# Evaluate curl return code and contents of CurlOutFFS file to #C# determine what to set ToDo to. ToDo is - without exception - #C# assigned a string like "CONTINUE", "NEXT_FILE", etc. ... #C# print -n -- "$ToDo" #C# ToDo confirmed to always have a value here return $Err } ... function fGetFileStatusFromSvr { typeset Err=0 ... \ ToDo=CONTINUE ... \ ... ... ToDo=$( fSendReqToSvr "$iSessMaxSecs" "$CurlCmdLine" ) Err=$? #C# ToDo contains null here ... return $Err } -- MTU Aero Engines AG Vorstand/Board of Management: Reiner Winkler, Vorsitzender/CEO; Dr. Rainer Martens, Michael Schreyögg, Dr. Stefan Weingartner Vorsitzender des Aufsichtsrats/Chairman of the Supervisory Board: Klaus Eberhardt Sitz der Gesellschaft/Registered Office: Muenchen Handelsregister/Commercial Register: Muenchen HRB 157206 Diese E-Mail sowie ihre Anhaenge enthalten MTU-eigene vertrauliche oder rechtlich geschuetzte Informationen. Wenn Sie nicht der beabsichtigte Empfaenger sind, informieren Sie bitte den Absender und loeschen Sie diese E-Mail sowie die Anhaenge. Das unbefugte Speichern, Kopieren oder Weiterleiten ist nicht gestattet. This e-mail and any attached documents are proprietary to MTU, confidential or protected by law. If you are not the intended recipient, please advise the sender and delete this message and its attachments. Any unauthorised storing, copying or distribution is prohibited. _______________________________________________ ast-users mailing list [email protected] http://lists.research.att.com/mailman/listinfo/ast-users
