bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unable to close a file descriptor using exec command


From: Greg Wooledge
Subject: Re: Unable to close a file descriptor using exec command
Date: Sun, 3 Mar 2024 19:05:49 -0500

On Sun, Mar 03, 2024 at 10:29:17PM +0000, Venkat Raman via Bug reports for the 
GNU Bourne Again SHell wrote:
> Repeat-By:
>         exec 2>&test1 commands freezes the terminal and unable to close the 
> fd.
> 
> Fix:
>         [Is there a sane  way to close the fd?]

You're using the wrong syntax.

To open a file (for writing + truncation):  exec 2>file

To open a file (for appending):  exec 2>>file

To close a file descriptor:  exec 2>&-


The command that you ran (exec 2>&test1) redirects stderr which is
normally opened to the terminal.  In order to get it back, you would
need to do something like  exec 2>&1   assuming stdout has not been
altered yet.

The shell prompt is normally written to stderr, so you won't see the
prompt until stderr is restored.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]