How to find next available file descriptor in Bash?
问题 How can I figure out if a file descriptor is currently in use in Bash? For example, if I have a script that reads, writes, and closes fd 3, e.g. exec 3< <(some command here) ... cat <&3 exec 3>&- what's the best way to ensure I'm not interfering with some other purpose for the descriptor that may have been set before my script runs? Do I need to put my whole script in a subshell? 回答1: In pure bash , you can use the following method to see if a given file descriptor ( 3 in this case) is