X-Spam-Check-By: sourceware.org Date: Wed, 25 Jan 2006 10:51:55 -0500 (EST) From: Igor Peshansky Reply-To: cygwin AT cygwin DOT com To: Eric Blake cc: cygwin AT cygwin DOT com Subject: Re: Shell (bash, (pd)ksh, zsh, /not/ ash) + exec + here-doc + redirect == trouble! In-Reply-To: <012520061548.27768.43D79DD500077D3900006C7822064246130A050E040D0C079D0A@comcast.net> Message-ID: References: <012520061548 DOT 27768 DOT 43D79DD500077D3900006C7822064246130A050E040D0C079D0A AT comcast DOT net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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 On Wed, 25 Jan 2006, Eric Blake wrote: > > You might want to quote <<'EOSH', but that's not the cause of your > > problem. Here's a funny thing: > > > > #!/bin/bash > > exec 5<&0 /bin/bash <<'EOSH' > > echo "First exec: Done." > > cat > > exec 0<&5 > > echo "Second exec: Done." > > exit 0 > > EOSH > > > > works for me. Don't ask me why, though. Perhaps Eric will chime in. > > Define "works for me". > > $ ./exectest.sh > First exec: Done. > exec 0<&5 > echo "Second exec: Done." > exit 0 D'oh! I was thrown off by the fact that I used "bash -xv" in my test script. Sorry for the noise. > Here, the cat uses fd 0 (which is still set to the pipe from the > here-doc), and consumes it by echoing the remainder of > the here-doc to stdout, so that when /bin/bash goes > to read the next line, fd 0 is at EOF, and you never execute > the "exec 0<&5" line in the shell. Thus, the process never > tries to duplicate fd 5 back to fd 0, and your example no longer > hangs waiting for input from the terminal. But it doesn't do what > was originally intended (that is, allow /bin/bash to execute > the remainder of the here-doc). Right. Your redirection order explanation is correct. Igor -- http://cs.nyu.edu/~pechtcha/ |\ _,,,---,,_ pechtcha AT cs DOT nyu DOT edu | igor AT watson DOT ibm DOT com ZZZzz /,`.-'`' -. ;-;;,_ Igor Peshansky, Ph.D. (name changed!) |,4- ) )-,_. ,\ ( `'-' old name: Igor Pechtchanski '---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow! "Las! je suis sot... -Mais non, tu ne l'es pas, puisque tu t'en rends compte." "But no -- you are no fool; you call yourself a fool, there's proof enough in that!" -- Rostand, "Cyrano de Bergerac" -- 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/