X-Spam-Check-By: sourceware.org
Message-ID: <43D78F0D.1030105@byu.net>
Date: Wed, 25 Jan 2006 07:45:33 -0700
From: Eric Blake <ebb9@byu.net>
User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)
MIME-Version: 1.0
CC: cygwin mailing-list <cygwin@cygwin.com>
Subject: Re: Shell (bash, (pd)ksh, zsh, /not/ ash) + exec + here-doc + redirect   == trouble!
References: <n2m-g.dr7491.3vv7b8v.1@buzzy-box.bavag> <43D78E29.4060504@byu.net>
In-Reply-To: <43D78E29.4060504@byu.net>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-IsSubscribed: yes
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Eric Blake on 1/25/2006 7:41 AM:
>>>=== begin testexec.sh ===
>>>#!/bin/ksh
>>>
>>>exec 5<&0 /bin/ksh <<EOSH
>>>echo "First exec: Done."
>>>exec 0<&5
>>>echo "Second exec: Done."
>>>exit 0
>>>EOSH
>>>==== end testexec.sh ====
> 
> 
> First line: This could be rewritten "exec /bin/ksh 5<&0 <<EOSH".  Either
> way, you are replacing the current shell with an invocation of /bin/ksh,
> and with fd 5 set to your current stdin, and then with fd 0 set to a pipe
> supplied by the contents of the here-doc.

P.S. If you had written this instead:

exec /bin/ksh <<EOSH 5<&0
echo "First exec: Done."
exec 0<&5
echo "Second exec: Done."
exit 0
EOSH

then you would have the same behavior as your second example (first,
replace fd 0 with the pipe from the here-doc, then copy fd 0 to fd 5; then
in the here-doc contents, when copying 5 back to 0, you are making no
changes).  With redirections, order is important.

- --
Life is short - so eat dessert first!

Eric Blake             ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFD148N84KuGfSFAYARApteAKDLmfTPjcwfNdu4j31Fg5866/HUsACfXQ7A
80k3Ne1IFXAFepx3UTmQyvI=
=+LHf
-----END PGP SIGNATURE-----

--
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/

