How to find next available file descriptor in Bash?

前端 未结 5 2132
离开以前
离开以前 2020-12-15 11:40

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<          


        
5条回答
  •  生来不讨喜
    2020-12-15 12:09

    For those who prefer one-liners and doesnt have Bash-4.1+ available:

    { seq 0 255; ls -1 /proc/$$/fd; } | sort -n | uniq -u | head -1
    

提交回复
热议问题