This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Shell (bash, (pd)ksh, zsh, /not/ ash) + exec + here-doc + redirect == trouble!


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]