If I remove the redirection, it works as expected.

(10:19:35) c89f8v08:/ # out=$(ls -l /tmp/junk 2>/dev/null || print -u2 
/tmp/junk NOT FOUND ; echo done) ; echo $out
done

(10:19:50) c89f8v08:/ # out=$(ls -l /tmp/junk || print -u2 /tmp/junk NOT FOUND 
; echo done) ; echo $out
/tmp/junk not found
/tmp/junk NOT FOUND
done





________________________________
 From: Truong Vu <[email protected]>
To: "[email protected]" <[email protected]> 
Sent: Tuesday, February 21, 2012 4:48 PM
Subject: Inconsistent return code from subshell
 

Hello,

We are running ksh Version JM 93t+ 2010-06-21 with the additional of the patch 
below:
--- src/cmd/ksh93/bltins/misc.c
+++ src/cmd/ksh93/bltins/misc.c 2011-02-22 13:03:35.783936889 +0000
@@ -273,7 +273,6 @@ int    b_dot_cmd(register int n,char *ar
        shp->st.self = &savst;
        shp->topscope = (Shscope_t*)shp->st.self;
        prevscope->save_tree = shp->var_tree;
-       shp->st.cmdname = argv[0];
       
 if(np)
                shp->st.filename =
 np->nvalue.rp->fname;
        nv_putval(SH_PATHNAMENOD, shp->st.filename ,NV_NOFREE);

We experience a problem that subshell return code is not correct.  It only 
returns the expected rc sometime.

Below show the return code of ls command on a non-existing file.  The rc=2

(16:26:33) c89f8v08:/ # /bin/ls /tmp/junk
/tmp/junk not found
(16:26:35) c89f8v08:/ # echo $?
2

If running the ls in a subshell, the return code is 0.

(16:26:37) c89f8v08:/ # out=$(/bin/ls /tmp/junk >/dev/null 2>&1)
(16:26:43) c89f8v08:/ # echo $?
0


Running in a loop (a few times), some time I do get the expected rc which is 2.

(16:27:19) c89f8v08:/ # i=1; while (( i < 20 ))
do
  out=$(/bin/ls /tmp/junk >/dev/null 2>&1)
  rc=$?
  print
 loop $i rc = $rc
  (( i++ ))
done


loop 1 rc = 0
loop 2 rc = 0
loop 3 rc = 0
loop 4 rc = 0
loop 5 rc = 0
loop 6 rc = 0
loop 7 rc = 0
loop 8 rc = 0
loop 9 rc = 0
loop 10 rc = 0
loop 11 rc = 2
loop 12 rc = 0
loop 13 rc = 0
loop 14 rc = 2
loop 15 rc = 0
loop 16 rc = 0
loop 17 rc = 2
loop 18 rc = 0
loop 19 rc = 0


The rc should always be 2 since the file does not exist.  But most of the time 
we see rc = 0.

(16:32:35) c89f8v08:/ # locale
LANG=C
LC_COLLATE="C"
LC_CTYPE="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_MESSAGES="C"
LC_ALL=

(16:33:08) c89f8v08:/ # uname -a
AIX c89f8v08 1 6 00CD05FF4C00
Is this a known problem?  Is there a fix for this?


Thanks,
Tru
_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers

Reply via email to