Joe Watkins Joe Watkins - 1 year ago 212
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!

Answer Source

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 "{}"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download