Joe Watkins Joe Watkins - 4 months ago 31
Bash Question

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

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

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 "{}"