Is there a way to close all the open file descriptors, without having an explicit list of them beforehand?
To answer literally, to close all open file descriptors for
However this really isn't a good idea since it will close the basic file descriptors the shell needs for input and output. If you do this, none of the programs you run will have their output displayed on the terminal (unless they write to the
What you may actually be looking to do is rather to close all file descriptors that are not part of the shell's basic operation. These are 0 for
Note also that
NOTE: Also using a glob instead of
For further information on the portability of
In recent versions of Bash (4.1 and onward, year 2009 and later) you can specify the file descriptor to close using a shell variable:
The feature had been in Korn shell already (since 1993?) but apparently took some time to make its way into Bash.
No. The kernel can close only one FD at a time, and bash does not have "group commands" for FDs.
If this is not for the shell itself but for a command to be run then you can use