Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

shell

eval

xargs

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

like image 978
Joe Watkins Avatar asked Nov 11 '10 11:11

Joe Watkins


Video Answer


1 Answers

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 "{}"
like image 189
Frédéric Hamidi Avatar answered Sep 19 '22 17:09

Frédéric Hamidi