[Centos] help with xargs and mv

Wed Feb 9 20:03:20 UTC 2005
Dag Wieers <dag at wieers.com>

On Wed, 9 Feb 2005, James B. Byrne wrote:

> On 9 Feb 2005 at 19:59, Dag Wieers wrote:
> 
> > Please do not add the * in workmv, but add it to the cmdline. Like:
> > 
> >  xargs -i mv ./mqueue/*'{}' ./mqueue/offline
> > 
> > The quotes around {} escapes the wildcard, so it loses its
> > special meaning. I would used ?? (or {df,qf}) instead of *, but
> > it makes no big difference. 
> 
> Ok, I cut out the leading '*' from the work file and used the 
> following command:
> 
> # cat workmid | xargs -i mv ./mqueue/*'{}' ./mqueue/offline
> mv: cannot stat `./mqueue/*j18IrbIn002131': No such file or 
> directory
> 
> #ll ./mqueue/*j18IrbIn002131
> -rw-------	1 root	root		1150 Feb  8 13:53 ./mqueue/dfj18IrbIn002131
> -rw-------	1 root	smmsp	1817 Feb  8 13:54 ./mqueue/qfj18IrbIn002131
> #
> 
> Now what is wrong?

Well, normally glob expansion is the shells work and I would have guessed 
(hoped) xargs would perform that for you, but it does not.

This is a good example why I usually don't write (even simple) scripts in 
bash. There are too many things you have to know and too many 
pitfalls and it often is more like trial-and-error programming :) There 
are other ways you can make it work like:

	cat workmid | xargs -i mv ./mqueue/df'{}' ./mqueue/qf'{}' ./mqueue/offline

But either you understand what's going on and adapt to that when it's 
necessary or shell scripting is simply not your thing. It's not my thing.

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