David Vasek schreef op 05-03-16 om 10:34:
> On Sat, 5 Mar 2016, Dmitrij D. Czarkoff wrote:
> 
>> So the goal of the diff is to replace something like
>>
>>  $ for src in ${files}; do [ -r "$src" ] && cp ${src} dst/; done
>>
>> with
>>
>>  $ yes n | cp -i ${files} dst/
>>
> 
> The former line doesn't prevent you from overwriting files in dst/ .
> More tests are necessary, which are in my opinion too complex for a
> simple interactive command line.
> 
> I've had burnt my hands a few times already with
>   $ yes n | cp -i ${files} dst/
> not working in agreement with the man page. Thank you, Timo, for
> bringing this up.

It's kind of ironic that we're arguing about the POSIX compliance of 'cp
-i' while the 'yes' command doesn't even exist in POSIX.

'pax', which is the POSIX replacement for 'cpio' and 'tar', has a -k
option for not overwriting existing files. A simple

    pax -rwk ${files} dst/

should do nicely.

- M.

Reply via email to