[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Necessary and sufficient conditions for using file descriptor redire
From: |
Koichi Murase |
Subject: |
Re: Necessary and sufficient conditions for using file descriptor redirection |
Date: |
Tue, 6 Apr 2021 15:29:33 +0900 |
2021年3月31日(水) 8:46 Peng Yu <pengyu.ut@gmail.com>:
> What are the necessary and sufficient conditions in which redirection
> to file descriptor should be used? Thanks.
I assume you are talking about the use case of `exec <redirections>'.
One case is that a user wants to keep the file opened among different
commands in an interactive session.
Another case is that one wants to open/close/reopen files with dynamic
conditions. Something like
while condition1; do
if condition2; then
exec 3> file
fi
if condition3; then
exec 3>&-
fi
done
But I agree that in many cases it can be rewritten without using `exec
redirections'. We can just sometimes write a code in a cleaner way
using `exec redirections'.
--
Koichi
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: Necessary and sufficient conditions for using file descriptor redirection,
Koichi Murase <=