Chinaunix

标题: How do I get the exit code of cmd1 in cmd1|cmd2|cmd3 请高手说明一下 [打印本页]

作者: johndoe    时间: 2006-02-14 15:48
标题: How do I get the exit code of cmd1 in cmd1|cmd2|cmd3 请高手说明一下
我查了这个在sh中的一个说明..但是我不是太明白.
How do I get the exit code of cmd1 in cmd1|cmd2|cmd3


exec 3>&1
       eval `
         # now, inside the `...`, fd4 goes to the pipe
         # whose other end is read and passed to eval;
         # fd1 is the normal standard output preserved
         # the line before with exec 3>&1
         exec 4>&1 >&3 3>&-
         {
           cmd1 4>&-; echo "ec1=$?;" >&4
         } | {
           cmd2 4>&-; echo "ec2=$?;" >&4
         } | cmd3
         echo "ec3=$?;" >&4
       `
请问 exec 3>&1,  exec 4>&1 >&3 3>&1 中的意思是什么?完全看不明白..请高手指点一下..多谢




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2