How 'exec 1<&-; exec 2<&-' work?

Eric Blake
Fri Sep 3 14:10:00 GMT 2010

On 09/03/2010 02:47 AM, Oleksandr Gavenko wrote:
> I intuitively change command to
> exec 1<&-; exec 2<&-; XWin -multiwindow &

> I really don't understand what magic exec do.

How could it be intuition if you don't know what it does?  A better 
description would be calling it what it was to you at the time - black 
magic copied from some online example you found.

> Can anyone point me?

'exec' with just file redirections makes those redirections affect the 
current shell and all subsequent processes started by the shell.  1<&- 
is a POSIX-mandated redirection for closing stdout; likewise 2<&- for 
closing stderr.  By closing stdout and stderr before starting XWin, you 
are making it so that XWin no longer ties up your terminal.

By the way, you could run this instead:

XWin -multiwindow >&- 2>&- &

and get the same effect without the 'exec'.

And none of this is cygwin-specific.

Eric Blake    +1-801-349-2682
Libvirt virtualization library

Problem reports:
Unsubscribe info:

More information about the Cygwin mailing list