help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Why 'exec' has to be used in with fd<>filename? And the


From: Eric Blake
Subject: Re: [Help-bash] Why 'exec' has to be used in with fd<>filename? And the difference between <> and >>?
Date: Wed, 12 Feb 2014 07:12:20 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0

On 02/12/2014 06:36 AM, Greg Wooledge wrote:

> and close() with a silly name inherited from the Bourne shell.
> 
>> Also, what is the benefit of using exec fd<>filename.
> 
> Pretty much the only time I would ever use <> in a script is with a
> socket connection.

Reading 'info coreutils' gives a valid use with 'shred':

   However, the command 'shred - >file' does not shred the contents of
FILE, since the shell truncates FILE before invoking 'shred'.  Use the
command 'shred file' or (if using a Bourne-compatible shell) the command
'shred - 1<>file' instead.

I've also personally hit cases where it is mandatory for use when
combining 'dd' commands to operate on an offset that is not a multiple
of the chunk size:

$command | { dd bs=512 seek=1 if=/dev/null && \
             dd ibs=1M obs=1M } 1<>output

for appending the output of $command at a 512 offset in file 'output'
while still processing it in much-more-efficient chunks of megabytes.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]