#!/usr/bin/env perl # # cpto - cp to the first argument # # $Id$ # Usage: ... | xargs cpto $dir # see also ./mvto # I wrote ./argswapping for this but it requires -n1 on xargs # move the last argument to the first non-option, then call cp # GNU cp allows options to be anywhere, I'll assume this is true # # for all cps we meet, so I'll just reorder them # my @opt = grep { /^-/ } @ARGV; my @arg = grep { !/^-/ } @ARGV; if ( @arg < 2 ) { die "fatal error: supply at least two arguments\n"; } else { my @cmd = ( 'cp', @opt, @arg[ 1 .. $#arg, 0 ] ); warn join( ' ', @cmd ), "\n"; exec(@cmd); }