[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Prevent file descriptor inheritance
From: |
Eric Blake |
Subject: |
Re: [Help-bash] Prevent file descriptor inheritance |
Date: |
Wed, 8 Aug 2018 10:06:37 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 |
On 08/08/2018 08:28 AM, R. Diez wrote:
Say I am using the file in a loop. If I close the file descriptor every
time before I run an external tool, I have to reopen the file and seek
to the last read position. Not very convenient.
Not true. You can close it on a per-command basis, while it still
remains open in the loop. That's what the 3<- file redirection operator
does when attached to a single command, rather than to exec.
OK, you can also stop file descriptor inheritance at every command, but
this is not practical. After all, you may want to consider all external
commands suspect, so you would have to do that for every command after
opening your file.
Or do that on a group of commands. Something like:
exec 3< mysecret
while read ...
do
{
process the just-read line
} 3<-
done <3
exec 3<-
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org