xargs to execute a string - what am I doing wrong?

Joe Watkins picture Joe Watkins · Nov 11, 2010 · Viewed 7.8k times · Source

I'm trying to rename all files in current directory such that upper case name is converted to lower. I'm trying to do it like this:

ls -1|gawk '{print "`mv "$0" "tolower($0)"`"}'|xargs -i -t eval {}

I have two files in the directory, Y and YY -t added for debugging, and output is:

eval `mv Y y`
xargs: eval: No such file or directory

if I execute the eval on its own, it works and moves Y to y.

I know there are other ways to achieve this, but I'd like to get this working if I can! Cheers

Answer

Frédéric Hamidi picture Frédéric Hamidi · Nov 11, 2010

eval is a shell builtin command, not a standalone executable. Thus, xargs cannot run it directly. You probably want:

ls -1 | gawk '{print "`mv "$0" "tolower($0)"`"}' | xargs -i -t sh -c "{}"