ファイル記述子を閉じるための構文混乱

ファイル記述子を閉じるための構文混乱

ファイル記述子を閉じる構文はほとんど混乱しています。たとえば、次のようになります。n>&-nというファイル記述子を閉じています。そうですか?

ただし、何かを別のファイル記述子にリダイレクトするにはこれを行う必要があるため、他のリダイレクトコマンドを使用するときにのみタグがファイル記述子として使用され、これが正しいことを知っていますn>&1&そう>なんですか?

また、シンボルを使用して次から/に、または次-にリダイレクトできます。stdinstdoutcat -

それでは、上記の規則を考慮すると、n>&-なぜファイル記述子を閉じるべきですか?次にリダイレクトされるようですstdin...

PS:参考までに私はhttp://tldp.org/LDP/abs/html/io-redirection.htmlそしてhttp://tldp.org/LDP/abs/html/special-chars.html

ベストアンサー1

ルールがあり、例外があります。

man bash | grep -C 3 '&-'
       Each redirection that may be preceded by a file descriptor  number  may
       instead be preceded by a word of the form {varname}.  In this case, for
       each redirection operator except >&- and <&-, the shell will allocate a
       file  descriptor  greater than or equal to 10 and assign it to varname.
       If >&- or <&- is preceded by {varname}, the value  of  varname  defines
       the file descriptor to close.

おすすめ記事