X-Spam-Check-By: sourceware.org Message-ID: From: "Buzz" Subject: Re: Shell (bash, (pd)ksh, zsh, /not/ ash) + exec + here-doc + redirect == trouble! References: <43D78E29 DOT 4060504 AT byu DOT net> Reply-To: cygwin mailing-list Organisation: Ehm... User-Agent: slrn/0.9.8.1 (Win32) Hamster/2.1.0.0 KorrNews/4.2.1 To: cygwin AT cygwin DOT com In-Reply-To: <43D78E29.4060504@byu.net> Lines: 85 Date: Wed, 25 Jan 2006 20:24:25 +0100 (MET) X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Op Wed, 25 Jan 2006 07:41:45 -0700 schreef Eric Blake in <43D78E29.4060504byu.net>: : : According to Bas van Gompel on 1/24/2006 10:11 PM: [script] : First line: This could be rewritten "exec /bin/ksh 5<&0 < In ash it prints '' : > First exec: Done. : > Second exec: Done. : > '', as I expected. Compare p.e. : Your expectation was wrong. Apparently. : > === begin testexec2.sh === : > #!/bin/bash : > : > echo 'echo "First exec: Done." : > exec 0<&5 : > echo "Second exec: Done." : > exit 0' |exec 5<&0 /bin/bash : > : > ==== end testexec2.sh ==== : : Here, you are doing something slightly different. The last line is a : pipeline, which must be applied before redirections. Which means that you : are exec'ing /bin/bash, with fd 0 set to the pipeline from the echo, then : fd 5 copied from fd 0. When the second "exec 0<&5" is reached, you copy : fd 5 back to fd 0, but since it was the same fd, it was effectively a : no-op. Therefore, /bin/bash continues to read the next line from fd 0, : and successfully prints "Second exec: Done." Right, my bad. Following shows the same (odd, IMO) behavior. === begin testexec2b.sh === #!/bin/bash exec 5<&0 echo 'echo "First exec: Done." exec 0<&5 echo "Second exec: Done." exit 0' |exec /bin/bash ==== end testexec2b.sh ==== I can work around this effect using -c, but thought it best to report anyway... L8r, Buzz. -- ) | | ---/ ---/ Yes, this | This message consists of true | I do not -- | | / / really is | and false bits entirely. | mail for ) | | / / a 72 by 4 +-------------------------------+ any1 but -- \--| /--- /--- .sigfile. | |perl -pe "s.u(z)\1.as." | me. 4^re -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/