[Centos] help with xargs and mv

Wed Feb 9 17:01:57 UTC 2005
Dag Wieers <dag at wieers.com>

On Wed, 9 Feb 2005, Dag Wieers wrote:

> On Wed, 9 Feb 2005, James B. Byrne wrote:
> > On 8 Feb 2005 at 23:14, Dag Wieers wrote:
> > 
> > > Compare this:
> > > 
> > >  echo -e "file1\nfile2\nfile3" | xargs echo '{}' blah
> > > 
> > > with:
> > > 
> > >  echo -e "file1\nfile2\nfile3" | xargs -i echo '{}' blah
> > 
> > Thank you for the advice on the -i switch. I had tried this 
> > earlier.  With the -i '{}' argument added then this is the result:
> > 
> > # ll -d ./mqueue/offline
> > drwxr-xr-x    2 root     root         4096 Feb  8 14:03 ./mqueue/offline
> > #
> > # cat workmv | xargs -i '{}' mv ./mqueue/'{}' ./mqueue/offline
> > xargs: {}: No such file or directory
> > #
> > # cat workmv | xargs -i '{}' mv ./mqueue/'{}' ./mqueue/offline/
> > xargs: {}: No such file or directory
> > #
> > # cat workmv | xargs -i '{}' mv --Target-Directory=./mqueue/offline ./mqueue/'{}'
> > xargs: {}: No such file or directory
> > #
> > # cat workmv | xargs -i '{}' mv --Target-Directory=./mqueue/offline/ ./mqueue/'{}'
> > xargs: {}: No such file or directory
> > #
> > 
> > P.S.
> > Also, thank you very much for the depository that you run. I use 
> > several of your packages.
> 
> Let me show you the manual entry again:
> 
>        --replace[=replace-str], -I replace-str, -i[replace-str]
>               Replace  occurences  of  replace-str  in the initial
>               arguments  with  names  read  from  standard  input.
>               Also,  unquoted  blanks  do not terminate arguments.
>               If replace-str is omitted, it defaults to "{}" (like
>               for 'find -exec').  Implies -x and -L 1.
> 
> So you either do:
> 
> 	echo -e "file1\nfile2\nfile3" | xargs -i echo '{}' blah
> or	echo -e "file1\nfile2\nfile3" | xargs -i echo '{}' blah/'{}'
> or	echo -e "file1\nfile2\nfile3" | xargs -i'**' echo '**' blah
> or	echo -e "file1\nfile2\nfile3" | xargs -I '**' echo '**' blah
> 
> This is correct:
> 
> 	xargs -i'{}'
> or	xargs -I '{}'
> 
> This is not:
> 
> 	xargs -i '{}'
> 
> Compare this to the manual entry to verify. The distinction is necessary 
> and important to allow for an '{}' default replace-str. Otherwise xargs 
> wouldn't know whether the next argument is in fact the replace-str or the 
> command to run !

And apparently, on RHEL3 the -I option does not exist:

	[dag at horsea dag]$ echo -e "file1\nfile2\nfile3" | xargs -I '**' echo '**' blah
	xargs: invalid option -- I
	Usage: xargs [-0prtx] [-e[eof-str]] [-i[replace-str]] [-l[max-lines]]
	       [-n max-args] [-s max-chars] [-P max-procs] [--null] [--eof[=eof-str]]
	       [--replace[=replace-str]] [--max-lines[=max-lines]] [--interactive]
	       [--max-chars=max-chars] [--verbose] [--exit] [--max-procs=max-procs]
	       [--max-args=max-args] [--no-run-if-empty] [--version] [--help]
	       [command [initial-arguments]]
	
	Report bugs to <bug-findutils at gnu.org>.


While on FC3, it should exist, but doesn't work:

	[root at emyn ~]# echo -e "file1\nfile2\nfile3" | xargs -I '**' echo '**' blah
	xargs: invalid option -- I
	Usage: xargs [-0prtx] [-E eof-str] [-e[eof-str]] [-I replace-str]
	       [-i[replace-str]] [-L max-lines] [-l[max-lines]] [-n max-args]
	       [-s max-chars] [-P max-procs] [--null] [--eof[=eof-str]]
	       [--replace[=replace-str]] [--max-lines[=max-lines]] [--interactive]
	       [--max-chars=max-chars] [--verbose] [--exit] [--max-procs=max-procs]
	       [--max-args=max-args] [--no-run-if-empty] [--version] [--help]
	       [command [initial-arguments]]

So you can forget about -I altogether on RHEL3. And I'll report is as a 
bug for FC3.

--   dag wieers,  dag at wieers.com,  http://dag.wieers.com/   --
[all I want is a warm bed and a kind word and unlimited power]