I'd like to run a shell command on each line taken from STDIN.In this case, I'd like to run xargs mv. For example, given two lines:mfoo foombar barI'd like to run:xargs mv mfoo fooxargs mv mbar barI've tried the following strategies with ruby, awk, and xargs. However, I'm doing it wrong:Just xargs:$ echo mbar bar\nmbaz baz | xargs mvusage: mv [-f | -i | -n] [-v] source target       mv [-f | -i | -n] [-v] source ... directoryThrough awk:$ echo mbar bar\nmbaz baz | awk '{ system(xargs $0) }'Through ruby:$ echo mbar bar\nmbaz baz | ruby -ne '`xargs mv`'$ lscat  foo  mbar mbazI have some questions:How do I do what I'm trying to do?What is wrong with each of my attempts?Is there a better way to think about what I'm trying to do?I'm especially confused that my xargs attempt isn't working because the following works:$ echo foo\nbar | xargs touch$ lsbar foo
How do I loop over the lines in STDIN and run a shell command?
bash;command line;awk;xargs
echo mbar bar\nmbaz baz | xargs mvWith xargs you should use the -t option to see what's going on. So in your above case if we were to invoke xargs with -t, what do we see:mv mbar bar mbaz bazSo obviously it's not correct. What happened was that xargs like a hungry crocodile, ate all the args fed to it via the pipe by echo. So you need a way to limit the release of arguments to the croc. And since you requested on a per-line basis, then what you need is the -l or the -L for POSIX option.echo mbar bar\nmbaz baz | xargs -l -t mvPOSIX-ly way:echo mbar bar\nmbaz baz | xargs -L 1 -t mvmv mbar barmv mbaz bazAnd this is what you wanted.H.T.H